From a8f94f267ba247cfe6862c05c939acb1207d91ec Mon Sep 17 00:00:00 2001 From: Fernando Ontiveros Date: Wed, 17 Oct 2012 14:24:28 -0400 Subject: [PATCH] CODE STYLE fixing class G, because the latest function was not included in the Code Style --- gulliver/system/class.g.php | 3962 ++++++++++++++++++----------------- 1 file changed, 1996 insertions(+), 1966 deletions(-) diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 57a512acc..a0c2843fb 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -1,50 +1,50 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * - */ - -/** - * @package gulliver.system - */ - -class G -{ - /** - * is_https - * @return void - */ - function is_https() - { - if(isset($_SERVER['HTTPS'])) - { - if($_SERVER['HTTPS']=='on') - return true; - else - return false; - } else { - return false; - } +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ + +/** + * @package gulliver.system + */ + +class G +{ + /** + * is_https + * @return void + */ + function is_https() + { + if(isset($_SERVER['HTTPS'])) + { + if($_SERVER['HTTPS']=='on') + return true; + else + return false; + } else { + return false; + } } /** * Fill array values (recursive) @@ -70,28 +70,28 @@ class G $arr = Array (); } return $arr; - } - - /** - * Generate Password Random - * @author maborak - * @access public - * @param Int - * @return String - */ - function generate_password($length = 8) - { - $password = ""; - $possible = "0123456789bcdfghjkmnpqrstvwxyz"; - $i = 0; - while($i<$length) { - $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); - if(!strstr($password, $char)) { - $password .= $char; - $i++; - } - } - return $password; + } + + /** + * Generate Password Random + * @author maborak + * @access public + * @param Int + * @return String + */ + function generate_password($length = 8) + { + $password = ""; + $possible = "0123456789bcdfghjkmnpqrstvwxyz"; + $i = 0; + while($i<$length) { + $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); + if(!strstr($password, $char)) { + $password .= $char; + $i++; + } + } + return $password; } /** * Array concat @@ -115,17 +115,17 @@ class G } } return $ret; - } - - /** - * Compare Variables - * var_compare(value,[var1,var2,varN]); - * @author maborak - * @access public - * @param void $value - * @param void $var1-N - * @return Boolean - */ + } + + /** + * Compare Variables + * var_compare(value,[var1,var2,varN]); + * @author maborak + * @access public + * @param void $value + * @param void $var1-N + * @return Boolean + */ function var_compare ($value = true, $varN) { $nums = func_num_args(); @@ -140,17 +140,17 @@ class G } } return true; - } - /** - * Emulate variable selector - * @author maborak - * @access public - * @param void - * @return void - */ + } + /** + * Emulate variable selector + * @author maborak + * @access public + * @param void + * @return void + */ function var_probe () { - //return (!$variable)? + //return (!$variable)? $nums = func_num_args(); $vars = func_get_args(); for ($i = 0; $i < $nums; $i ++) { @@ -170,14 +170,14 @@ class G */ function &getVersion () { - //majorVersion.minorVersion-SvnRevision + //majorVersion.minorVersion-SvnRevision return '3.0-1'; - } - - /** - * getIpAddress - * @return string $ip - */ + } + + /** + * getIpAddress + * @return string $ip + */ function getIpAddress () { if (getenv( 'HTTP_CLIENT_IP' )) { @@ -225,8 +225,8 @@ class G * @param string $newFatalErrorHandler default value null * * @return boolean true - */ - /*public static*/ + */ + /*public static*/ function &setFatalErrorHandler ($newFatalErrorHandler = null) { if (isset( $newFatalErrorHandler )) { @@ -267,8 +267,8 @@ class G /*public static*/ function fatalErrorHandler ($buffer) { - // The ereg function has been DEPRECATED as of PHP 5.3.0. - // if (ereg("(error:)(.+)(:)(.+)(:)(.+)(/", "", $regs[2] ); G::customErrorLog( 'FATAL', $err, '', 0, '' ); @@ -314,9 +314,9 @@ class G G::customErrorLog( $type, $msg, $file, $line ); break; case E_STRICT: - $type = "STRICT"; //dont show STRICT Errors - //if (defined ("ERROR_LOG_NOTICE_ERROR") && ERROR_LOG_NOTICE_ERROR) - // G::customErrorLog ($type, $msg, $file, $line); + $type = "STRICT"; //dont show STRICT Errors + //if (defined ("ERROR_LOG_NOTICE_ERROR") && ERROR_LOG_NOTICE_ERROR) + // G::customErrorLog ($type, $msg, $file, $line); break; default: $type = "ERROR ($errno)"; @@ -361,9 +361,9 @@ class G print "
"; print ""; - print " - - + print " + + "; for ($i = $start; $i <= $end; $i ++) { $str = @highlight_string( "", true ); @@ -374,7 +374,7 @@ class G $str = substr( $str, 0, $pos1 ) . substr( $str, $pos1 + 5, $pos2 - ($pos1 + 5) ) . substr( $str, $pos2 + 5 ); ($i == $line) ? $bgcolor = "bgcolor=#ffccaa" : $bgcolor = "bgcolor=#ffffff"; - print " + print ""; } @@ -430,8 +430,8 @@ class G global $SERVER_ADMIN; print "

Error!

"; - print "An error occurred while executing this script. Please - contact the $SERVER_ADMIN to + print "An error occurred while executing this script. Please + contact the $SERVER_ADMIN to report this error."; print "

"; print "Here is the information provided by the script:"; @@ -458,8 +458,8 @@ class G */ function encrypt ($string, $key) { - //print $string; - // if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) { + //print $string; + // if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) { if (strpos( $string, '|', 0 ) !== false) return $string; $result = ''; @@ -469,13 +469,13 @@ class G $char = chr( ord( $char ) + ord( $keychar ) ); $result .= $char; } - //echo $result . '
'; + //echo $result . '
'; $result = base64_encode( $result ); $result = str_replace( '/', '°', $result ); $result = str_replace( '=', '', $result ); - // } - // else - // $result = $string; + // } + // else + // $result = $string; return $result; } @@ -490,8 +490,8 @@ class G */ function decrypt ($string, $key) { - // if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) { - //if (strpos($string, '|', 0) !== false) return $string; + // if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) { + //if (strpos($string, '|', 0) !== false) return $string; $result = ''; $string = str_replace( '°', '/', $string ); $string_jhl = explode( "?", $string ); @@ -506,9 +506,9 @@ class G } if (! empty( $string_jhl[1] )) $result .= '?' . $string_jhl[1]; - // } - // else - // $result = $string; + // } + // else + // $result = $string; return $result; } @@ -522,8 +522,8 @@ class G */ function lookup ($target) { - //if( eregi("[a-zA-Z]", $target) ) - if (preg_match( "[a-zA-Z]", $target )) //Made compatible to PHP 5.3 + //if( eregi("[a-zA-Z]", $target) ) + if (preg_match( "[a-zA-Z]", $target )) //Made compatible to PHP 5.3 $ntarget = gethostbyname( $target ); else $ntarget = gethostbyaddr( $target ); @@ -539,13 +539,13 @@ class G ); $oldumask = umask( 0 ); while (! @is_dir( dirname( end( $folder_path ) ) ) && dirname( end( $folder_path ) ) != '/' && dirname( end( $folder_path ) ) != '.' && dirname( end( $folder_path ) ) != '') - array_push( $folder_path, dirname( end( $folder_path ) ) ); //var_dump($folder_path); die; + array_push( $folder_path, dirname( end( $folder_path ) ) ); //var_dump($folder_path); die; while ($parent_folder_path = array_pop( $folder_path )) if (! @is_dir( $parent_folder_path )) if (! @mkdir( $parent_folder_path, $rights )) - //trigger_error ("Can't create folder \"$parent_folder_path\".", E_USER_WARNING); + //trigger_error ("Can't create folder \"$parent_folder_path\".", E_USER_WARNING); umask( $oldumask ); } /** @@ -603,7 +603,7 @@ class G return true; } else { if ($createPath) { - //TODO:: Define Environment constants: Devel (0777), Production (0770), ... + //TODO:: Define Environment constants: Devel (0777), Production (0770), ... G::mk_dir( $strPath, 0777 ); } else return false; @@ -711,10 +711,10 @@ class G */ function LoadSkin ($strSkinName) { - //print $strSkinName; - //now, we are using the skin, a skin is a file in engine/skin directory + //print $strSkinName; + //now, we are using the skin, a skin is a file in engine/skin directory $file = G::ExpandPath( "skins" ) . $strSkinName . ".php"; - //G::pr($file); + //G::pr($file); if (file_exists( $file )) { require_once ($file); return; @@ -784,7 +784,7 @@ class G */ function LoadAllPluginModelClasses () { - //Get the current Include path, where the plugins directories should be + //Get the current Include path, where the plugins directories should be if (! defined( 'PATH_SEPARATOR' )) { define( 'PATH_SEPARATOR', (substr( PHP_OS, 0, 3 ) == 'WIN') ? ';' : ':' ); } @@ -801,7 +801,7 @@ class G } } } - //Include also the extendGulliverClass that could have some new definitions for fields + //Include also the extendGulliverClass that could have some new definitions for fields if (file_exists( $possiblePath . 'classes' . PATH_SEP . 'class.extendGulliver.php' )) { include_once $possiblePath . 'classes' . PATH_SEP . 'class.extendGulliver.php'; } @@ -824,14 +824,14 @@ class G return; $temp = $strTemplateName . ".php"; $file = G::ExpandPath( 'templates' ) . $temp; - // Check if its a user template + // Check if its a user template if (file_exists( $file )) { - //require_once( $file ); + //require_once( $file ); include ($file); } else { - // Try to get the global system template + // Try to get the global system template $file = PATH_TEMPLATE . PATH_SEP . $temp; - //require_once( $file ); + //require_once( $file ); if (file_exists( $file )) include ($file); } @@ -915,8 +915,8 @@ class G */ static function parseURI ($uri, $isRestRequest = false) { - //*** process the $_POST with magic_quotes enabled - // The magic_quotes_gpc feature has been DEPRECATED as of PHP 5.3.0. + //*** 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) { $_POST = G::strip_slashes( $_POST ); } @@ -951,7 +951,7 @@ class G for ($i = 2; $i < count( $aRequestUri ); $i ++) { $decoded = G::decrypt( urldecode( $aRequestUri[$i] ), URL_KEY ); if ($decoded == 'sWì›') { - $decoded = $VARS[$i]; //this is for the string "../" + $decoded = $VARS[$i]; //this is for the string "../" } $plain .= '/' . $decoded; } @@ -979,7 +979,7 @@ class G $buffer[1] = ''; } - //request type + //request type define( 'REQUEST_TYPE', ($buffer[1] != "" ? $buffer[1] : 'html') ); $toparse = substr( $buffer[0], 1, strlen( $buffer[0] ) - 1 ); @@ -996,12 +996,12 @@ class G $args['SYS_COLLECTION'] = array_shift( $uriVars ); $args['SYS_TARGET'] = array_shift( $uriVars ); - //to enable more than 2 directories...in the methods structure + //to enable more than 2 directories...in the methods structure while (count( $uriVars ) > 0) { $args['SYS_TARGET'] .= '/' . array_shift( $uriVars ); } - /* Fix to prevent use uxs skin outside siplified interface, + /* 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') { $config = System::getSystemConfiguration(); @@ -1014,7 +1014,7 @@ class G public function parseRestUri ($requestUri) { $args = array (); - //$args['SYS_TEMP'] = $requestUri[1]; + //$args['SYS_TEMP'] = $requestUri[1]; define( 'SYS_TEMP', $requestUri[2] ); $restUri = ''; @@ -1022,7 +1022,7 @@ class G $restUri .= '/' . $requestUri[$i]; } - $args['SYS_LANG'] = 'en'; // TODO, this can be set from http header + $args['SYS_LANG'] = 'en'; // TODO, this can be set from http header $args['SYS_SKIN'] = ''; $args['SYS_COLLECTION'] = ''; $args['SYS_TARGET'] = $restUri; @@ -1077,7 +1077,7 @@ class G { header( 'Content-Type: text/css' ); - //First get Skin info + //First get Skin info $filenameParts = explode( "-", $filename ); $skinName = $filenameParts[0]; $skinVariant = "skin"; @@ -1100,15 +1100,15 @@ class G } } - //Read Configuration File + //Read Configuration File $xmlConfiguration = file_get_contents( $configurationFile ); $xmlConfigurationObj = G::xmlParser( $xmlConfiguration ); $baseSkinDirectory = dirname( $configurationFile ); $directorySize = G::getDirectorySize( $baseSkinDirectory ); $mtime = $directorySize['maxmtime']; - //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. - //$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); + //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. + //$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); $gmt_mtime = gmdate( "D, d M Y H:i:s", $mtime ) . " GMT"; @@ -1116,8 +1116,8 @@ class G header( 'ETag: "' . md5( $mtime . $filename ) . '"' ); header( "Last-Modified: " . $gmt_mtime ); header( 'Cache-Control: public' ); - header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 30 * 60 * 60 * 24 ) . " GMT" ); //1 month - //header("Expires: " . gmdate("D, d M Y H:i:s", time () + 60*60*24 ) . " GMT"); //1 day - tempor + header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 30 * 60 * 60 * 24 ) . " GMT" ); //1 month + //header("Expires: " . gmdate("D, d M Y H:i:s", time () + 60*60*24 ) . " GMT"); //1 day - tempor if (isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] )) { if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) { header( 'HTTP/1.1 304 Not Modified' ); @@ -1139,30 +1139,30 @@ class G $gmt_mtimeNow = gmdate( "D, d M Y H:i:s", $mtimeNow ) . " GMT"; $outputHeader .= " Date: $gmt_mtimeNow*/\n"; $output = ""; - //Base files + //Base files switch (strtolower( $skinVariant )) { case "extjs": - //Base + //Base $baseCSSPath = PATH_SKIN_ENGINE . "base" . PATH_SEP . "baseCss" . PATH_SEP; $output .= file_get_contents( $baseCSSPath . 'ext-all-notheme.css' ); - //$output .= file_get_contents ( $publicExtPath . 'ext-all.css' ); + //$output .= file_get_contents ( $publicExtPath . 'ext-all.css' ); - //Classic Skin + //Classic Skin $extJsSkin = 'xtheme-gray'; - /*$publicExtPath = PATH_SKIN_ENGINE."base". PATH_SEP."css". PATH_SEP; - $output .= file_get_contents ( $publicExtPath . $extJsSkin . '.css' ); - $output .= file_get_contents ( $publicExtPath . 'pmos-' . $extJsSkin . '.css' ); + /*$publicExtPath = PATH_SKIN_ENGINE."base". PATH_SEP."css". PATH_SEP; + $output .= file_get_contents ( $publicExtPath . $extJsSkin . '.css' ); + $output .= file_get_contents ( $publicExtPath . 'pmos-' . $extJsSkin . '.css' ); */ - //adding the extend css for extjs-pmos - //TODO: move this files to pmos-xthem.. - //$cssThemeExtensions = glob(PATH_TPL . "*/css/extjs-extend/{$extJsSkin}.css"); - //foreach($cssThemeExtensions as $cssThemeExtensionFile) - //$helper->addFile($cssThemeExtensionFile); - //$output .= file_get_contents ( $cssThemeExtensionFile ); - // $classicCSSPath=PATH_SKIN_ENGINE."base". PATH_SEP."css". PATH_SEP; - // $output .= file_get_contents ( $classicCSSPath . 'sprite.css' ); - //$output .= file_get_contents ( $classicCSSPath . 'sprite_ie.css' ); + //adding the extend css for extjs-pmos + //TODO: move this files to pmos-xthem.. + //$cssThemeExtensions = glob(PATH_TPL . "*/css/extjs-extend/{$extJsSkin}.css"); + //foreach($cssThemeExtensions as $cssThemeExtensionFile) + //$helper->addFile($cssThemeExtensionFile); + //$output .= file_get_contents ( $cssThemeExtensionFile ); + // $classicCSSPath=PATH_SKIN_ENGINE."base". PATH_SEP."css". PATH_SEP; + // $output .= file_get_contents ( $classicCSSPath . 'sprite.css' ); + //$output .= file_get_contents ( $classicCSSPath . 'sprite_ie.css' ); break; @@ -1172,56 +1172,56 @@ class G } - //Get Browser Info + //Get Browser Info $infoBrowser = G::browser_detection( 'full_assoc' ); $browserName = $infoBrowser['browser_working']; if (isset( $infoBrowser[$browserName . '_data'] )) { if ($infoBrowser[$browserName . '_data'][0] != "") { $browserName = $infoBrowser[$browserName . '_data'][0]; } - } - //print "

$browserName

"; - //G::pr($infoBrowser); - - - //Read Configuration File - $xmlConfiguration = file_get_contents ( $configurationFile ); - $xmlConfigurationObj=G::xmlParser($xmlConfiguration); - - //G::pr($xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['cssFiles']['__CONTENT__'][$tempSkin]['__CONTENT__'] ); - $skinFilesArray=$xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['cssFiles']['__CONTENT__'][$skinVariant]['__CONTENT__']['cssFile'] ; - //G::pr($skinFilesArray); - foreach($skinFilesArray as $keyFile => $cssFileInfo){ - //G::pr($cssFileInfo); - //TODO: Also review browser versions for restrictions - $enabledBrowsers=explode(",",$cssFileInfo['__ATTRIBUTES__']['enabledBrowsers']); - $disabledBrowsers=explode(",",$cssFileInfo['__ATTRIBUTES__']['disabledBrowsers']); - - if(((in_array($browserName, $enabledBrowsers))||(in_array('ALL', $enabledBrowsers)))&&(!(in_array($browserName, $disabledBrowsers)))){ - //G::pr($cssFileInfo['__ATTRIBUTES__']['file']); - if($cssFileInfo['__ATTRIBUTES__']['file'] == 'rtl.css') { - G::LoadClass('serverConfiguration'); - $oServerConf =& serverConf::getSingleton(); - if (!(defined('SYS_LANG'))) { - if (isset($_SERVER['HTTP_REFERER'])) { - $syss = explode('://', $_SERVER['HTTP_REFERER']); - $sysObjets = explode('/', $syss['1']); - $sysLang = $sysObjets['2']; - } else { - $sysLang = 'en'; - } - } else { - $sysLang = SYS_LANG; - } - if ($oServerConf->isRtl($sysLang)) { - $output .= file_get_contents ( $baseSkinDirectory . PATH_SEP.'css'.PATH_SEP.$cssFileInfo['__ATTRIBUTES__']['file'] ); - } - } else { - $output .= file_get_contents ( $baseSkinDirectory . PATH_SEP.'css'.PATH_SEP.$cssFileInfo['__ATTRIBUTES__']['file'] ); - } - } + } + //print "

$browserName

"; + //G::pr($infoBrowser); + + + //Read Configuration File + $xmlConfiguration = file_get_contents ( $configurationFile ); + $xmlConfigurationObj=G::xmlParser($xmlConfiguration); + + //G::pr($xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['cssFiles']['__CONTENT__'][$tempSkin]['__CONTENT__'] ); + $skinFilesArray=$xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['cssFiles']['__CONTENT__'][$skinVariant]['__CONTENT__']['cssFile'] ; + //G::pr($skinFilesArray); + foreach($skinFilesArray as $keyFile => $cssFileInfo){ + //G::pr($cssFileInfo); + //TODO: Also review browser versions for restrictions + $enabledBrowsers=explode(",",$cssFileInfo['__ATTRIBUTES__']['enabledBrowsers']); + $disabledBrowsers=explode(",",$cssFileInfo['__ATTRIBUTES__']['disabledBrowsers']); + + if(((in_array($browserName, $enabledBrowsers))||(in_array('ALL', $enabledBrowsers)))&&(!(in_array($browserName, $disabledBrowsers)))){ + //G::pr($cssFileInfo['__ATTRIBUTES__']['file']); + if($cssFileInfo['__ATTRIBUTES__']['file'] == 'rtl.css') { + G::LoadClass('serverConfiguration'); + $oServerConf =& serverConf::getSingleton(); + if (!(defined('SYS_LANG'))) { + if (isset($_SERVER['HTTP_REFERER'])) { + $syss = explode('://', $_SERVER['HTTP_REFERER']); + $sysObjets = explode('/', $syss['1']); + $sysLang = $sysObjets['2']; + } else { + $sysLang = 'en'; + } + } else { + $sysLang = SYS_LANG; + } + if ($oServerConf->isRtl($sysLang)) { + $output .= file_get_contents ( $baseSkinDirectory . PATH_SEP.'css'.PATH_SEP.$cssFileInfo['__ATTRIBUTES__']['file'] ); + } + } else { + $output .= file_get_contents ( $baseSkinDirectory . PATH_SEP.'css'.PATH_SEP.$cssFileInfo['__ATTRIBUTES__']['file'] ); + } + } } - //Remove comments.. + //Remove comments.. $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" ); $output = preg_replace( array_keys( $regex ), $regex, $output ); @@ -1252,7 +1252,7 @@ class G global $translation; - //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. + //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. $userAgent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if (file_exists( $filename )) $mtime = filemtime( $filename ); @@ -1263,7 +1263,7 @@ class G header( 'ETag: "' . md5( $mtime . $filename ) . '"' ); header( "Last-Modified: " . $gmt_mtime ); header( 'Cache-Control: public' ); - header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 30 * 60 * 60 * 24 ) . " GMT" ); //1 month + header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 30 * 60 * 60 * 24 ) . " GMT" ); //1 month if (isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] )) { if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) { header( 'HTTP/1.1 304 Not Modified' ); @@ -1299,14 +1299,14 @@ class G $typefile = $typearray[count( $typearray ) - 1]; $filename = $file; - //trick to generate the translation.language.js file , merging two files and then minified the content. + //trick to generate the translation.language.js file , merging two files and then minified the content. if (strtolower( $typefile ) == 'js' && $typearray[0] == 'translation') { $output = G::streamJSTranslationFile( $filename, $typearray[1] ); print $output; return; } - //trick to generate the big css file for ext style . + //trick to generate the big css file for ext style . if (strtolower( $typefile ) == 'css' && $folderarray[count( $folderarray ) - 2] == 'css') { $output = G::streamCSSBigFile( $typearray[0] ); print $output; @@ -1370,7 +1370,7 @@ class G G::sendHeaders( $filename, 'application/x-tar', $download, $downloadFileName ); break; default: - //throw new Exception ( "Unknown type of file '$file'. " ); + //throw new Exception ( "Unknown type of file '$file'. " ); G::sendHeaders( $filename, 'application/octet-stream', $download, $downloadFileName ); break; break; @@ -1398,7 +1398,7 @@ class G $cf = $cachePath . "ext-draw2d-cache.$checksum.js"; $cfStored = G::getCacheFileNameByPattern( $cachePath, 'ext-draw2d-cache.*.js' ); - //error_log("draw2d.js ".$checksum ."==". $cfStored['checksum']); + //error_log("draw2d.js ".$checksum ."==". $cfStored['checksum']); if (is_file( $cfStored['filename'] ) && $checksum == $cfStored['checksum']) { $output = file_get_contents( $cf ); } else { @@ -1408,9 +1408,9 @@ class G $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/wz_jsgraphics.js' ) ); $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/mootools.js' ) ); $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/moocanvas.js' ) ); - $output .= file_get_contents( $pathJs . 'ext/draw2d.js' ); //already minified + $output .= file_get_contents( $pathJs . 'ext/draw2d.js' ); //already minified file_put_contents( $cf, $output ); - //error_log("draw2d.js writting ".$cf); + //error_log("draw2d.js writting ".$cf); } break; case 'ext-all.js': @@ -1426,8 +1426,8 @@ class G if (is_file( $cfStored['filename'] )) @unlink( $cfStored['filename'] ); - $output .= file_get_contents( $pathJs . 'ext/ext-all.js' ); //already minified - $output .= file_get_contents( $pathJs . 'ext/ux/ux-all.js' ); //already minified + $output .= file_get_contents( $pathJs . 'ext/ext-all.js' ); //already minified + $output .= file_get_contents( $pathJs . 'ext/ux/ux-all.js' ); //already minified $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/pmos-common.js' ) ); $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/ux/miframe.js' ) ); $output .= JSMin::minify( file_get_contents( $pathJs . 'ext/ux.locationbar/Ext.ux.LocationBar.js' ) ); @@ -1442,25 +1442,25 @@ class G $oHeadPublisher = & headPublisher::getSingleton(); foreach ($oHeadPublisher->maborakFiles as $fileJS) { $output .= JSMin::minify( file_get_contents( $fileJS ) ); - //$output .= G::trimSourceCodeFile ($fileJS ); + //$output .= G::trimSourceCodeFile ($fileJS ); } break; case 'maborak.loader.js': $oHeadPublisher = & headPublisher::getSingleton(); foreach ($oHeadPublisher->maborakLoaderFiles as $fileJS) { $output .= JSMin::minify( file_get_contents( $fileJS ) ); - //$output .= G::trimSourceCodeFile ($fileJS ); + //$output .= G::trimSourceCodeFile ($fileJS ); } break; default: - //$output = file_get_contents ( $filename ) ; + //$output = file_get_contents ( $filename ) ; $output = JSMin::minify( file_get_contents( $filename ) ); - //$output = G::trimSourceCodeFile ($filename ); + //$output = G::trimSourceCodeFile ($filename ); } print $output; break; case 'css': - //$output = JSMin::minify ( file_get_contents ( $filename) ); + //$output = JSMin::minify ( file_get_contents ( $filename) ); print G::trimSourceCodeFile( $filename ); break; default: @@ -1483,38 +1483,38 @@ class G $content = ''; $line = ''; - //no optimizing code + //no optimizing code if ($handle) { while (! feof( $handle )) { - //$line = trim( fgets($handle, 16096) ) . "\n" ; + //$line = trim( fgets($handle, 16096) ) . "\n" ; $line = fgets( $handle, 16096 ); $content .= $line; } fclose( $handle ); } return $content; - //end NO optimizing code - //begin optimizing code - /* - if ($handle) { - while (!feof($handle)) { - $lastChar = ( strlen ( $line ) > 5 ) ? $line[strlen($line)-1] : ''; - - $line = trim( fgets($handle, 16096) ) ; - if ( substr ($line,0,2 ) == '//' ) $line = ''; - $firstChar = ( strlen ( $line ) > 6 ) ? strtolower($line[0]) : ''; - if ( ord( $firstChar ) > 96 && ord($firstChar) < 122 && $lastChar == ';') - $content .= ''; - else - $content .= "\n"; - // $content .= '('.$firstChar . $lastChar . ord( $firstChar ).'-'. ord( $lastChar ) . ")\n"; - - $content .= $line; - } - fclose($handle); - } + //end NO optimizing code + //begin optimizing code + /* + if ($handle) { + while (!feof($handle)) { + $lastChar = ( strlen ( $line ) > 5 ) ? $line[strlen($line)-1] : ''; + + $line = trim( fgets($handle, 16096) ) ; + if ( substr ($line,0,2 ) == '//' ) $line = ''; + $firstChar = ( strlen ( $line ) > 6 ) ? strtolower($line[0]) : ''; + if ( ord( $firstChar ) > 96 && ord($firstChar) < 122 && $lastChar == ';') + $content .= ''; + else + $content .= "\n"; + // $content .= '('.$firstChar . $lastChar . ord( $firstChar ).'-'. ord( $lastChar ) . ")\n"; + + $content .= $line; + } + fclose($handle); + } */ - //end optimizing code + //end optimizing code $index = 0; @@ -1560,10 +1560,10 @@ class G } header( 'Content-Type: ' . $contentType ); - //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. + //if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor. $userAgent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if (preg_match( "/msie/i", $userAgent )) { - //if ( ereg("msie", $userAgent)) { + //if ( ereg("msie", $userAgent)) { header( 'Pragma: cache' ); $mtime = filemtime( $filename ); @@ -1571,7 +1571,7 @@ class G header( 'ETag: "' . md5( $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 + header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + 60 * 10 ) . " GMT" ); //ten minutes return; } @@ -1617,7 +1617,7 @@ class G function virtualURI ($url, $convertionTable, &$realPath) { foreach ($convertionTable as $urlPattern => $localPath) { - // $urlPattern = addcslashes( $urlPattern , '/'); + // $urlPattern = addcslashes( $urlPattern , '/'); $urlPattern = addcslashes( $urlPattern, './' ); $urlPattern = '/^' . str_replace( array ('*','?' ), array ('.*','.?' @@ -1678,11 +1678,11 @@ class G return $e; } - /* formatNumber - * - * @author David Callizaya - * @param int/string $num - * @return string number + /* formatNumber + * + * @author David Callizaya + * @param int/string $num + * @return string number */ function formatNumber ($num, $language = 'latin') { @@ -1693,35 +1693,35 @@ class G return $snum; } - /* Returns a date formatted according to the given format string - * @author David Callizaya - * @param string $format The format of the outputted date string - * @param string $datetime Date in the format YYYY-MM-DD HH:MM:SS + /* Returns a date formatted according to the given format string + * @author David Callizaya + * @param string $format The format of the outputted date string + * @param string $datetime Date in the format YYYY-MM-DD HH:MM:SS */ function formatDate ($datetime, $format = 'Y-m-d', $lang = '') { if ($lang === '') $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. + $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'); - // Spanish months + // Spanish months $ARR_MONTHS['es'] = array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre" ); - // English months + // English months $ARR_MONTHS['en'] = array ("January","February","March","April","May","June","July","August","September","October","November","December" ); - // Spanish days + // Spanish days $ARR_WEEKDAYS['es'] = array ("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado" ); - // English days + // English days $ARR_WEEKDAYS['en'] = array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" ); @@ -1785,14 +1785,14 @@ class G * ******************************************************************************************************* */ - //scape the literal + //scape the literal switch ($lang) { case 'es': $format = str_replace( ' de ', '[of]', $format ); break; } - //first we must formatted the string + //first we must formatted the string $format = str_replace( 'yyyy', '{YEAR}', $format ); $format = str_replace( 'yy', '{year}', $format ); @@ -1810,19 +1810,19 @@ class G if ($lang === '') $lang = defined( SYS_LANG ) ? SYS_LANG : 'en'; - $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. + $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. - $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 + $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 - $h = isset( $time[0] ) ? $time[0] : '00'; //hour - $i = isset( $time[1] ) ? $time[1] : '00'; //minute - $s = isset( $time[2] ) ? $time[2] : '00'; //second + $h = isset( $time[0] ) ? $time[0] : '00'; //hour + $i = isset( $time[1] ) ? $time[1] : '00'; //minute + $s = isset( $time[2] ) ? $time[2] : '00'; //second $MONTHS = Array (); @@ -1833,7 +1833,7 @@ class G $d = (int) $day; $dd = G::complete_field( $day, 2, 1 ); - //missing D + //missing D $M = $MONTHS[$month]; @@ -1850,7 +1850,7 @@ class G $ret = str_replace( $names, $values, $format ); - //recovering the original literal + //recovering the original literal switch ($lang) { case 'es': $ret = str_replace( '[of]', ' de ', $ret ); @@ -1875,14 +1875,14 @@ class G $array2 = (array) $array2; } - // This wrapper for array_diff rekeys the array returned + // This wrapper for array_diff rekeys the array returned $valid_array = array_diff( $array1, $array2 ); - // reinstantiate $array1 variable + // reinstantiate $array1 variable $array1 = array (); - // 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 + // 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; } @@ -1898,21 +1898,21 @@ class G { $campo = trim( $campo ); switch ($tipo) { - case 1: //number + case 1: //number $long = $long - strlen( $campo ); for ($i = 1; $i <= $long; $i ++) { $campo = "0" . $campo; } break; - case 2: //string + case 2: //string $long = $long - strlen( $campo ); for ($i = 1; $i <= $long; $i ++) { $campo = " " . $campo; } break; - case 3: //float + case 3: //float if ($campo != "0") { $vals = explode( ".", $long ); $ints = $vals[0]; @@ -1930,7 +1930,7 @@ class G $intscampo = "0" . $intscampo; } - //los decimales pueden ser 0 uno o dos + //los decimales pueden ser 0 uno o dos $decs = $decs - strlen( $decscampo ); for ($i = 1; $i <= $decs; $i ++) { $decscampo = $decscampo . "0"; @@ -1958,10 +1958,10 @@ class G return $campo; } - /* Escapes special characters in a string for use in a SQL statement - * @author David Callizaya - * @param string $sqlString The string to be escaped - * @param string $DBEngine Target DBMS + /* Escapes special characters in a string for use in a SQL statement + * @author David Callizaya + * @param string $sqlString The string to be escaped + * @param string $DBEngine Target DBMS */ function sqlEscape ($sqlString, $DBEngine = DB_ADAPTER) { @@ -1973,7 +1973,7 @@ class G case 'myxml': $sqlString = str_replace( '"', '""', $sqlString ); return str_replace( "'", "''", $sqlString ); - //return str_replace(array('"',"'"),array('""',"''"),stripslashes($sqlString)); + //return str_replace(array('"',"'"),array('""',"''"),stripslashes($sqlString)); default: return addslashes( stripslashes( $sqlString ) ); } @@ -1999,17 +1999,17 @@ class G break; } } - /* Returns a sql string with @@parameters replaced with its values defined - * 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" - * @author David Callizaya + /* Returns a sql string with @@parameters replaced with its values defined + * 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" + * @author David Callizaya */ function replaceDataField ($sqlString, $result, $DBEngine = 'mysql') { @@ -2019,7 +2019,7 @@ class G $result = $result + G::getSystemConstants(); $__textoEval = ""; $u = 0; - //$count=preg_match_all('/\@(?:([\@\%\#\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))/',$sqlString,$match,PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); + //$count=preg_match_all('/\@(?:([\@\%\#\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))/',$sqlString,$match,PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); $count = preg_match_all( '/\@(?:([\@\%\#\=\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*?)*)\))/', $sqlString, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); if ($count) { for ($r = 0; $r < $count; $r ++) { @@ -2028,122 +2028,122 @@ class G if (! is_array( $result[$match[2][$r][0]] )) { $__textoEval .= substr( $sqlString, $u, $match[0][$r][1] - $u ); $u = $match[0][$r][1] + strlen( $match[0][$r][0] ); - //Mysql quotes scape + //Mysql quotes scape if (($match[1][$r][0] == '@') && (isset( $result[$match[2][$r][0]] ))) { $__textoEval .= "\"" . G::sqlEscape( $result[$match[2][$r][0]], $DBEngine ) . "\""; continue; - } - //URL encode - if (($match[1][$r][0]=='%')&&(isset($result[$match[2][$r][0]]))) { - $__textoEval.=urlencode($result[$match[2][$r][0]]);continue; - } - //Double quoted parameter - if (($match[1][$r][0]=='Q')&&(isset($result[$match[2][$r][0]]))) { - $__textoEval.='"'.addcslashes($result[$match[2][$r][0]],'\\"').'"';continue; - } - //Single quoted parameter - if (($match[1][$r][0]=='q')&&(isset($result[$match[2][$r][0]]))) { - $__textoEval.="'".addcslashes($result[$match[2][$r][0]],'\\\'')."'";continue; - } - //Substring (Sub replaceDataField) - if (($match[1][$r][0]=='!')&&(isset($result[$match[2][$r][0]]))) { - $__textoEval.=G::replaceDataField($result[$match[2][$r][0]],$result);continue; - } - //Call function - if (($match[1][$r][0]==='')&&($match[2][$r][0]==='')&&($match[3][$r][0]!=='')) { - eval('$strAux = ' . $match[3][$r][0] . '(\'' . addcslashes(G::replaceDataField(stripslashes($match[4][$r][0]),$result),'\\\'') . '\');'); - - if ($match[3][$r][0] == "G::LoadTranslation") { - $arraySearch = array("'"); - $arrayReplace = array("\\'"); - - $strAux = str_replace($arraySearch, $arrayReplace, $strAux); - } - - $__textoEval .= $strAux; continue; - } - //Non-quoted - if (($match[1][$r][0]=='#')&&(isset($result[$match[2][$r][0]]))) { - $__textoEval.=G::replaceDataField($result[$match[2][$r][0]],$result);continue; - } - //Non-quoted = - if (($match[1][$r][0]=='=')&&(isset($result[$match[2][$r][0]]))) { - $__textoEval.=G::replaceDataField($result[$match[2][$r][0]],$result);continue; - } - } - } - } - $__textoEval.=substr($sqlString,$u); - return $__textoEval; - } - - /** - * Replace Grid Values - * The tag @>GRID-NAME to open the grid and @])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+)?/', $strContentAux, $arrayMatch1, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); - - if ($iOcurrences) { - $arrayGrid = array(); - for ($i = 0; $i <= $iOcurrences - 1; $i++) { - $arrayGrid[] = $arrayMatch1[2][$i][0]; - } - - $arrayGrid = array_unique($arrayGrid); - - foreach ($arrayGrid as $index => $value) { - $grdName = $value; - $strContentAux1 = $strContentAux; - $strContentAux = null; - $ereg = "/^(.*)@>" . $grdName . "(.*)@<" . $grdName . "(.*)$/"; - - while (preg_match($ereg, $strContentAux1, $arrayMatch2)) { - $strData = null; - - if (isset($aFields[$grdName]) && is_array($aFields[$grdName])) { - foreach ($aFields[$grdName] as $aRow) { - foreach ($aRow as $sKey => $vValue) { - if (!is_array($vValue)) { - $aRow[$sKey] = nl2br($aRow[$sKey]); - } - } - $strData = $strData . G::replaceDataField($arrayMatch2[2], $aRow); - } - } - $strContentAux1 = $arrayMatch2[1]; - $strContentAux = $strData . $arrayMatch2[3] . $strContentAux; - } - $strContentAux = $strContentAux1 . $strContentAux; - } - } - $strContentAux = str_replace($nrthtml, $nrt, $strContentAux); - $sContent = $strContentAux; - - foreach ($aFields as $sKey => $vValue) { - if (!is_array($vValue)) { - $aFields[$sKey] = nl2br($aFields[$sKey]); - } - } - $sContent = G::replaceDataField($sContent, $aFields); - - return $sContent; + } + //URL encode + if (($match[1][$r][0]=='%')&&(isset($result[$match[2][$r][0]]))) { + $__textoEval.=urlencode($result[$match[2][$r][0]]);continue; + } + //Double quoted parameter + if (($match[1][$r][0]=='Q')&&(isset($result[$match[2][$r][0]]))) { + $__textoEval.='"'.addcslashes($result[$match[2][$r][0]],'\\"').'"';continue; + } + //Single quoted parameter + if (($match[1][$r][0]=='q')&&(isset($result[$match[2][$r][0]]))) { + $__textoEval.="'".addcslashes($result[$match[2][$r][0]],'\\\'')."'";continue; + } + //Substring (Sub replaceDataField) + if (($match[1][$r][0]=='!')&&(isset($result[$match[2][$r][0]]))) { + $__textoEval.=G::replaceDataField($result[$match[2][$r][0]],$result);continue; + } + //Call function + if (($match[1][$r][0]==='')&&($match[2][$r][0]==='')&&($match[3][$r][0]!=='')) { + eval('$strAux = ' . $match[3][$r][0] . '(\'' . addcslashes(G::replaceDataField(stripslashes($match[4][$r][0]),$result),'\\\'') . '\');'); + + if ($match[3][$r][0] == "G::LoadTranslation") { + $arraySearch = array("'"); + $arrayReplace = array("\\'"); + + $strAux = str_replace($arraySearch, $arrayReplace, $strAux); + } + + $__textoEval .= $strAux; continue; + } + //Non-quoted + if (($match[1][$r][0]=='#')&&(isset($result[$match[2][$r][0]]))) { + $__textoEval.=G::replaceDataField($result[$match[2][$r][0]],$result);continue; + } + //Non-quoted = + if (($match[1][$r][0]=='=')&&(isset($result[$match[2][$r][0]]))) { + $__textoEval.=G::replaceDataField($result[$match[2][$r][0]],$result);continue; + } + } + } + } + $__textoEval.=substr($sqlString,$u); + return $__textoEval; + } + + /** + * Replace Grid Values + * The tag @>GRID-NAME to open the grid and @])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+)?/', $strContentAux, $arrayMatch1, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); + + if ($iOcurrences) { + $arrayGrid = array(); + for ($i = 0; $i <= $iOcurrences - 1; $i++) { + $arrayGrid[] = $arrayMatch1[2][$i][0]; + } + + $arrayGrid = array_unique($arrayGrid); + + foreach ($arrayGrid as $index => $value) { + $grdName = $value; + $strContentAux1 = $strContentAux; + $strContentAux = null; + $ereg = "/^(.*)@>" . $grdName . "(.*)@<" . $grdName . "(.*)$/"; + + while (preg_match($ereg, $strContentAux1, $arrayMatch2)) { + $strData = null; + + if (isset($aFields[$grdName]) && is_array($aFields[$grdName])) { + foreach ($aFields[$grdName] as $aRow) { + foreach ($aRow as $sKey => $vValue) { + if (!is_array($vValue)) { + $aRow[$sKey] = nl2br($aRow[$sKey]); + } + } + $strData = $strData . G::replaceDataField($arrayMatch2[2], $aRow); + } + } + $strContentAux1 = $arrayMatch2[1]; + $strContentAux = $strData . $arrayMatch2[3] . $strContentAux; + } + $strContentAux = $strContentAux1 . $strContentAux; + } + } + $strContentAux = str_replace($nrthtml, $nrt, $strContentAux); + $sContent = $strContentAux; + + foreach ($aFields as $sKey => $vValue) { + if (!is_array($vValue)) { + $aFields[$sKey] = nl2br($aFields[$sKey]); + } + } + $sContent = G::replaceDataField($sContent, $aFields); + + return $sContent; } - /* Load strings from a XMLFile. - * @author David Callizaya - * @parameter $languageFile An xml language file. - * @parameter $languageId (es|en|...). - * @parameter $forceParse Force to read and parse the xml file. + /* Load strings from a XMLFile. + * @author David Callizaya + * @parameter $languageFile An xml language file. + * @parameter $languageId (es|en|...). + * @parameter $forceParse Force to read and parse the xml file. */ function loadLanguageFile ($filename, $languageId = '', $forceParse = false) { @@ -2153,7 +2153,7 @@ class G $languageFile = basename( $filename, '.xml' ); $cacheFile = substr( $filename, 0, - 3 ) . $languageId; if (($forceParse) || (! file_exists( $cacheFile )) || (filemtime( $filename ) > filemtime( $cacheFile ))) - //|| ( filemtime(__FILE__) > filemtime($cacheFile)) + //|| ( filemtime(__FILE__) > filemtime($cacheFile)) { $languageDocument = new Xml_document(); $languageDocument->parseXmlFile( $filename ); @@ -2176,16 +2176,16 @@ class G require ($cacheFile); } } - /* Funcion auxiliar Temporal: - * Registra en la base de datos los labels xml usados en el sistema - * @author David Callizaya + /* Funcion auxiliar Temporal: + * Registra en la base de datos los labels xml usados en el sistema + * @author David Callizaya */ function registerLabel ($id, $label) { return 1; $dbc = new DBConnection(); $ses = new DBSession( $dbc ); - $ses->Execute( G::replaceDataField( 'REPLACE INTO `TRANSLATION` (`TRN_CATEGORY`, `TRN_ID`, `TRN_LANG`, `TRN_VALUE`) VALUES + $ses->Execute( G::replaceDataField( 'REPLACE INTO `TRANSLATION` (`TRN_CATEGORY`, `TRN_ID`, `TRN_LANG`, `TRN_VALUE`) VALUES ("LABEL", @@ID, "' . SYS_LANG . '", @@LABEL);', array ('ID' => $id,'LABEL' => ($label !== null ? $label : '') ) ) ); } @@ -2388,17 +2388,17 @@ class G $defaultTranslations = Array (); $foreignTranslations = Array (); - //if the default translations table doesn't exist we can't proceed + //if the default translations table doesn't exist we can't proceed if (! is_file( PATH_LANGUAGECONT . 'translation.en' )) return NULL; - //load the translations table + //load the translations table require_once (PATH_LANGUAGECONT . 'translation.en'); $defaultTranslations = $translation; - //if some foreign language was requested and its translation file exists + //if some foreign language was requested and its translation file exists if ($lang != 'en' && file_exists( PATH_LANGUAGECONT . 'translation.' . $lang )) { - require_once (PATH_LANGUAGECONT . 'translation.' . $lang); //load the foreign translations table + require_once (PATH_LANGUAGECONT . 'translation.' . $lang); //load the foreign translations table $foreignTranslations = $translation; } @@ -2425,7 +2425,7 @@ class G { global $translation; - // if the second parameter $lang is an array does mean it was especified to use as data + // if the second parameter $lang is an array does mean it was especified to use as data if (is_array( $lang )) { $data = $lang; $lang = SYS_LANG; @@ -2543,14 +2543,14 @@ class G { global $RBAC; - //the session is expired, go to login page, - //the login page is login/login.html + //the session is expired, go to login page, + //the login page is login/login.html if (! isset( $_SESSION )) { header( 'location: ' . G::expandUri( $urlLogin ) ); die(); } - //$permission is an array, we'll verify all permission to allow access. + //$permission is an array, we'll verify all permission to allow access. if (is_array( $permission )) $aux = $permission; else @@ -2563,7 +2563,7 @@ class G $sw = 1; } - //you don't have access to this page + //you don't have access to this page if ($sw == 0) { header( 'location: ' . G::expandUri( $urlNoAccess ) ); die(); @@ -2626,9 +2626,9 @@ class G } else { $res[] = $tmp_key . "=" . rawurlencode( $v ); } - /* - 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) ); + /* + 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) ); */ } $separator = ini_get( 'arg_separator.output' ); @@ -2716,7 +2716,7 @@ class G $res = $RBAC->userCanAccess( $aux[$i] ); if ($res == 1) $sw = 1; - //print " $aux[$i] $res $sw
"; + //print " $aux[$i] $res $sw
"; } if ($sw == 0 && $urlNoAccess != "") { @@ -2726,14 +2726,14 @@ class G $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]); - //header ("location: /$sys/$lang/$skin/$login/$loginhtml"); + //header ("location: /$sys/$lang/$skin/$login/$loginhtml"); header( "location: /fluid/mNE/o9A/mNGm1aLiop3V4qU/dtij4J°gmaLPwKDU3qNn2qXanw" ); die(); } if ($sw == 0) { header( "location: /fluid/mNE/o9A/mNGm1aLiop3V4qU/dtij4J°gmaLPwKDU3qNn2qXanw" ); - //header ( "location: /sys/" . SYS_LANG . "/" . SYS_SKIN . "/login/noViewPage.html" ); + //header ( "location: /sys/" . SYS_LANG . "/" . SYS_SKIN . "/login/noViewPage.html" ); die(); } } @@ -2763,7 +2763,7 @@ class G $new_val .= $car; } else { if ($car2 != chr( 92 )) { - //print " xmlvar: $new_val -- $car -- $car2
"; + //print " xmlvar: $new_val -- $car -- $car2
"; $new_val .= chr( 92 ) . $car; } else $new_val .= $car; @@ -2828,16 +2828,16 @@ class G $resWidth = $width * $percent; $resHeight = $height * $percent; - // Resample + // Resample $image_p = imagecreatetruecolor( $resWidth, $resHeight ); imagealphablending( $image_p, false ); imagesavealpha( $image_p, true ); $background = imagecolorallocate( $image_p, 0, 0, 0 ); - ImageColorTransparent( $image_p, $background ); // make the new temp image all transparent + ImageColorTransparent( $image_p, $background ); // make the new temp image all transparent - //Assume 3 channels if we can't find that information + //Assume 3 channels if we can't find that information if (! array_key_exists( "channels", $imageInfo )) $imageInfo["channels"] = 3; $memoryNeeded = Round( ($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] + Pow( 2, 16 )) * 1.95 ) / (1024 * 1024); @@ -2924,7 +2924,7 @@ class G $sUID = str_replace( '.', '0', uniqid( rand( 0, 999999999 ), true ) ); } while (strlen( $sUID ) != 32); return $sUID; - //return strtoupper(substr(uniqid(rand(0, 9), false),0,14)); + //return strtoupper(substr(uniqid(rand(0, 9), false),0,14)); } /** @@ -2992,93 +2992,93 @@ class G } else { return (utf8_encode( utf8_decode( $string ) ) == $string); } - } - - - /** - * Return date in Y-m-d format - * - * @author Fernando Ontiveros Lira - * @access public - * @return void - */ - function CurDate($sFormat='') - { - $sFormat = ($sFormat != '')? $sFormat : 'Y-m-d H:i:s'; - - return date($sFormat); - } - - /** - * Return the System defined constants and Application variables - * Constants: SYS_* - * Sessions : USER_* , URS_* - */ - function getSystemConstants($params=null) - { - $t1 = G::microtime_float(); - $sysCon = array(); - - if (defined("SYS_LANG")) { - $sysCon["SYS_LANG"] = SYS_LANG; - } - - if (defined("SYS_SKIN")) { - $sysCon["SYS_SKIN"] = SYS_SKIN; - } - - if (defined("SYS_SYS")) { - $sysCon["SYS_SYS"] = SYS_SYS; - } - - $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"] : ""; - - //############################################################################################### - // 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)) { - G::LoadClass("sessions"); - - $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"]; - $sysCon["PROCESS"] = $params->appData["PROCESS"]; - $sysCon["TASK"] = $params->appData["TASK"]; - $sysCon["INDEX"] = $params->appData["INDEX"]; - - if (empty($sysCon["USER_LOGGED"])) { - $sysCon["USER_LOGGED"] = $params->appData["USER_LOGGED"]; - $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 - */ - function capitalizeWords( $text ) - { - return ucwords($text); + } + + + /** + * Return date in Y-m-d format + * + * @author Fernando Ontiveros Lira + * @access public + * @return void + */ + function CurDate($sFormat='') + { + $sFormat = ($sFormat != '')? $sFormat : 'Y-m-d H:i:s'; + + return date($sFormat); + } + + /** + * Return the System defined constants and Application variables + * Constants: SYS_* + * Sessions : USER_* , URS_* + */ + function getSystemConstants($params=null) + { + $t1 = G::microtime_float(); + $sysCon = array(); + + if (defined("SYS_LANG")) { + $sysCon["SYS_LANG"] = SYS_LANG; + } + + if (defined("SYS_SKIN")) { + $sysCon["SYS_SKIN"] = SYS_SKIN; + } + + if (defined("SYS_SYS")) { + $sysCon["SYS_SYS"] = SYS_SYS; + } + + $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"] : ""; + + //############################################################################################### + // 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)) { + G::LoadClass("sessions"); + + $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"]; + $sysCon["PROCESS"] = $params->appData["PROCESS"]; + $sysCon["TASK"] = $params->appData["TASK"]; + $sysCon["INDEX"] = $params->appData["INDEX"]; + + if (empty($sysCon["USER_LOGGED"])) { + $sysCon["USER_LOGGED"] = $params->appData["USER_LOGGED"]; + $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 + */ + function capitalizeWords( $text ) + { + return ucwords($text); } /** @@ -3128,19 +3128,19 @@ class G 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. + // 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. if (isset( $r['value'] ) && trim( $r['value'] ) != '') { $cv['__VALUE__'] = $r['value']; } - // end added code + // end added code $cv['__CONTENT__'] = array (); $cv['__CONTENT__']['_p'] = &$ary; $ary = &$cv['__CONTENT__']; } elseif ($r['type'] == 'complete') { - if (isset( $ary[$t] )) { // same as open + if (isset( $ary[$t] )) { // same as open if (isset( $ary[$t][0] )) $ary[$t][] = array (); else @@ -3177,7 +3177,7 @@ class G * * @return void */ - // _Internal: Remove recursion in result array + // _Internal: Remove recursion in result array function _del_p (&$ary) { foreach ($ary as $k => $v) { @@ -3199,7 +3199,7 @@ class G * * @return void */ - // Array to XML + // Array to XML function ary2xml ($cary, $d = 0, $forcetag = '') { $res = array (); @@ -3238,7 +3238,7 @@ class G * * @return void */ - // Insert element into array + // Insert element into array function ins2ary (&$ary, $element, $pos) { $ar1 = array_slice( $ary, 0, $pos ); @@ -3246,8 +3246,8 @@ class G $ary = array_merge( $ar1, array_slice( $ary, $pos ) ); } - /* - * Xml parse collection functions + /* + * Xml parse collection functions *************************************** end **********************************************/ /** @@ -3337,18 +3337,18 @@ class G function sys_get_temp_dir () { if (! function_exists( 'sys_get_temp_dir' )) { - // Based on http://www.phpit.net/ - // article/creating-zip-tar-archives-dynamically-php/2/ - // Try to get from environment variable + // Based on http://www.phpit.net/ + // article/creating-zip-tar-archives-dynamically-php/2/ + // Try to get from environment variable if (! empty( $_ENV['TMP'] )) { return realpath( $_ENV['TMP'] ); } else if (! empty( $_ENV['TMPDIR'] )) { return realpath( $_ENV['TMPDIR'] ); } else if (! empty( $_ENV['TEMP'] )) { return realpath( $_ENV['TEMP'] ); - } else { // Detect by creating a temporary file - // Try to use system's temporary directory - // as random name shouldn't exist + } else { // Detect by creating a temporary file + // Try to use system's temporary directory + // as random name shouldn't exist $temp_file = tempnam( md5( uniqid( rand(), TRUE ) ), '' ); if ($temp_file) { $temp_dir = realpath( dirname( $temp_file ) ); @@ -3396,9 +3396,9 @@ class G } if ($result) { - //verifing if the response has a composite response into a guid value of the first row. + //verifing if the response has a composite response into a guid value of the first row. $tmp = explode( ' ', trim( $aList[0]->guid ) ); - if (sizeof( $tmp ) >= 2) { //the guid can't has a space, so this should be a ws response + if (sizeof( $tmp ) >= 2) { //the guid can't has a space, so this should be a ws response $Resp->status_code = $tmp[0]; $Resp->message = substr( $aList[0]->guid, strpos( $aList[0]->guid, ' ' ) + 1 ); } else { @@ -3416,1375 +3416,1375 @@ class G $Resp->message = "1 Bad respose type for ({$prop})"; } return $Resp; - } - - /** - * Validate and emai address in complete forms, - * - * @author Erik A.O. - * i.e. if the param. is 'erik a.o. ' - * -> returns a object within $o->email => erik@colosa.com and $o->name => erik A.O. in other case returns false - * - */ - function emailAddress($sEmail){ - $o = new stdClass(); - - if( strpos($sEmail, '<') !== false ) { - preg_match('/([\"\w@\.-_\s]*\s*)?(<(\w+[\.-]?\w+]*@\w+([\.-]?\w+)*\.\w{2,3})+>)/', $sEmail, $matches); - - if( isset($matches[1]) && $matches[3]){ - $o->email = $matches[3]; - $o->name = $matches[1]; - - return $o; - } - - return false; - } - else { - preg_match('/\w+[\.-]?\w+]*@\w+([\.-]?\w+)*\.\w{2,3}+/', $sEmail, $matches); - if( isset($matches[0]) ){ - $o->email = $matches[0]; - $o->name = ''; - return $o; - } - - return false; - } - } - - /** - * JSON encode - * - * @author Erik A.O. - */ - function json_encode($Json){ - if( function_exists('json_encode') ){ - return json_encode($Json); - } else { - G::LoadThirdParty('pear/json', 'class.json'); - $oJSON = new Services_JSON(); - return $oJSON->encode($Json); - } - } - - /** - * JSON decode - * - * @author Erik A.O. - */ - function json_decode($Json){ - if( function_exists('json_decode') ){ - return json_decode($Json); - } else { - G::LoadThirdParty('pear/json', 'class.json'); - $oJSON = new Services_JSON(); - return $oJSON->decode($Json); - } - } - - /** - * isHttpRequest - * - * @return boolean true or false - */ - function isHttpRequest(){ - 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 - * @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 ') - * array('to'=>array('email1', 'some name '), '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 - */ - function sendMail($from, $fromName, $address, $subject, $body) - { - // require_once "classes/class.pmFunctions.php"; - G::LoadClass("pmFunctions"); - G::LoadThirdParty('phpmailer', 'class.phpmailer'); - $setup = getEmailConfiguration(); - - 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'); - } - - $passwd = $setup['MESS_PASSWORD']; - $passwdDec = G::decrypt($passwd,'EMAILENCRYPT'); - $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; - $mail->IsHTML (true); - $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) { - $mail->AddBCC($emails[0], $emails[1]); - } - - return $mail->Send() ? true : $mail->ErrorInfo; - } - - /** - * Envelope a emails collection from a string or array - * @author Erik Amaru Ortiz - * @param mixed $address the possibles values are: - * string - * array('email1', 'some name ') - * array('to'=>array('email1', 'some name '), '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', ...) - * ) - */ - function envelopEmailAddresses($address) - { - $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. - * @return (string) type of variable - */ - public function gettype($var) { - switch ($var) { - case is_null($var): - $type='NULL'; - break; - - case is_bool($var): - $type='boolean'; - break; - - case is_float($var): - $type='double'; - break; - - case is_int($var): - $type='integer'; - break; - - case is_string($var): - $type='string'; - break; - - case is_array($var): - $type='array'; - break; - - case is_object($var): - $type='object'; - break; - - case is_resource($var): - $type='resource'; - break; - - default: - $type='unknown type'; - break; - } - - return $type; - } - - 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; - } - - function getMemoryUsage(){ - $size = memory_get_usage(true); - $unit=array('B','Kb','Mb','Gb','Tb','Pb'); - return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; - } - - function getFormatUserList($format, $aUserInfo){ - - 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; - } - - function getModel($model){ - require_once "classes/model/$model.php"; - return new $model(); - } - - /** - * Recursive Is writeable function - * - * @author Erik Amaru Ortiz - * - * @param $path path to scan recursively the write permission - * @param $pattern pattern to filter some especified files - * @return if the $path, assuming that is a directory -> all files in it are writeables or not - */ - function is_rwritable($path, $pattern='*') - { - $files = G::rglob($pattern, 0, $path); - foreach ($files as $file) { - if( ! is_writable($file) ) - return false; - } - return true; - } - - /** - * Recursive version of glob php standard function - * - * @author Erik Amaru Ortiz - * - * @param $path path to scan recursively the write permission - * @param $flags to notive glob function - * @param $pattern pattern to filter some especified files - * @return array containing the recursive glob results - */ - function rglob($pattern='*', $flags = 0, $path='') - { - $paths = glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT); - $files = glob($path.$pattern, $flags); - foreach ($paths as $path) { - $files = array_merge($files, G::rglob($pattern, $flags, $path)); - } - return $files; - } -function browser_detection( $which_test, $test_excludes='', $external_ua_string='' ) -{ - /* - uncomment the global variable declaration if you want the variables to be available on - a global level throughout your php page, make sure that php is configured to support - the use of globals first! - Use of globals should be avoided however, and they are not necessary with this script - /* - /* - global $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; - */ - 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. - if ( $external_ua_string ) - { - $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 - */ - if ( !$b_repeat ) - { - //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; - $b_success = false;// boolean for if browser found in main test - $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 = ''; - $ua_type = 'bot';// default to bot since you never know with bots - $webkit_type = ''; - $webkit_type_number = ''; - - // set the excludes if required - if ( $test_excludes ) - { - switch ( $test_excludes ) - { - 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: - die( 'Error: bad $test_excludes parameter 2 used: ' . $test_excludes ); - 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. - */ - 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'] ); - } - else - { - $browser_user_agent = ''; - } - - /* - pack the browser type array, in this order - the order is important, because opera must be tested first, then omniweb [which has safari - data in string], same for konqueror, then safari, then gecko, since safari navigator user - agent id's with 'gecko' in string. - Note that $b_dom_browser is set for all modern dom browsers, this gives you a default to use. - - array[0] = id string for useragent, array[1] is if dom capable, array[2] is working name - for browser, array[3] identifies navigator useragent type - - Note: all browser strings are in lower case to match the strtolower output, this avoids - possible detection errors - - Note: These are the navigator user agent types: - bro - modern, css supporting browser. - bbro - basic browser, text only, table only, defective css implementation - bot - search type spider - dow - known download agent - lib - standard http libraries - mobile - handheld or mobile browser, set using $mobile_test - */ - // known browsers, list will be updated routinely, check back now and then - $a_browser_types = array( - array( 'opera', true, 'op', 'bro' ), - array( 'msie', true, 'ie', 'bro' ), - // webkit before gecko because some webkit ua strings say: like gecko - array( 'webkit', true, 'webkit', 'bro' ), - // konq will be using webkit soon - array( 'konqueror', true, 'konq', 'bro' ), - // covers Netscape 6-7, K-Meleon, Most linux versions, uses moz array below - 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 - - // search engine spider bots: - 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' ), - - // various http utility libaries - 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' ), - - // download apps - array( 'getright', false, 'getright', 'dow' ), - array( 'wget', false, 'wget', 'dow' ),// open source downloader, obeys robots.txt - - // netscape 4 and earlier tests, put last so spiders don't get caught - array( 'mozilla/4.', false, 'ns', 'bbro' ), - array( 'mozilla/3.', false, 'ns', 'bbro' ), - array( 'mozilla/2.', false, 'ns', 'bbro' ) - ); - - //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 - */ - $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' ); - - /* - 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. - */ - $a_webkit_types = array( 'arora', 'chrome', 'epiphany', 'gtklauncher', 'konqueror', 'midori', 'omniweb', 'safari', 'uzbl', 'applewebkit', 'webkit' ); - - /* - 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. - */ - $i_count = count( $a_browser_types ); - for ( $i = 0; $i < $i_count; $i++ ) - { - //unpacks browser array, assigns to variables, need to not assign til found in string - $browser_temp = $a_browser_types[$i][0];// text string to id browser from array - - if ( strstr( $browser_user_agent, $browser_temp ) ) - { - /* - 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; - $browser_name = $browser_temp;// text string to id browser from array - - // assign values based on match of user agent string - $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 - - switch ( $browser_working ) - { - // 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; - $browser_number = G::get_item_version( $browser_user_agent, 'mozilla' ); - 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 - $moz_rv_full = G::get_item_version( $browser_user_agent, 'rv' ); - // this slices them back off for math comparisons - $moz_rv = substr( $moz_rv_full, 0, 3 ); - - // this is to pull out specific mozilla versions, firebird, netscape etc.. - $j_count = count( $a_moz_types ); - for ( $j = 0; $j < $j_count; $j++ ) - { - if ( strstr( $browser_user_agent, $a_moz_types[$j] ) ) - { - $moz_type = $a_moz_types[$j]; - $moz_number = G::get_item_version( $browser_user_agent, $moz_type ); - 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 - */ - if ( !$moz_rv ) - { - // you can use this if you are running php >= 4.2 - if ( function_exists( 'floatval' ) ) - { - $moz_rv = floatval( $moz_number ); - } - else - { - $moz_rv = substr( $moz_number, 0, 3 ); - } - $moz_rv_full = $moz_number; - } - // this corrects the version name in case it went to the default 'rv' for the test - if ( $moz_type == 'rv' ) - { - $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 - G::get_set_count( 'set', 0 ); - $moz_release_date = G::get_item_version( $browser_user_agent, 'gecko/' ); - /* - 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; - */ - if ( ( $moz_release_date < 20020400 ) || ( $moz_rv < 1 ) ) - { - $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/ - */ - $browser_number = G::get_item_version( $browser_user_agent, $browser_name, true, 'trident/' ); - // construct the proper real number if it's in compat mode and msie 8.0/9.0 - if ( strstr( $browser_number, '7.' ) && strstr( $browser_user_agent, 'trident/5' ) ) - { - // 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; - } - elseif ( strstr( $browser_number, '7.' ) && strstr( $browser_user_agent, 'trident/4' ) ) - { - // 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 - if ( $browser_number >= 9 ) - { - $ie_version = 'ie9x'; - } - // 7/8 were not yet quite to standards levels but getting there - elseif ( $browser_number >= 7 ) - { - $ie_version = 'ie7x'; - } - // then test for IE 5x mac, that's the most problematic IE out there - elseif ( strstr( $browser_user_agent, 'mac') ) - { - $ie_version = 'ieMac'; - } - // ie 5/6 are both very weak in standards compliance - elseif ( $browser_number >= 5 ) - { - $ie_version = 'ie5x'; - } - elseif ( ( $browser_number > 3 ) && ( $browser_number < 5 ) ) - { - $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': - $browser_number = G::get_item_version( $browser_user_agent, $browser_name ); - // 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/ - 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/' ); - } - - if ( $browser_number < 5 )// opera 4 wasn't very useable. - { - $b_safe_browser = false; - } - break; - /* - note: webkit returns always the webkit version number, not the specific user - agent version, ie, webkit 583, not chrome 0.3 - */ - case 'webkit': - // note that this is the Webkit version number - $browser_number = G::get_item_version( $browser_user_agent, $browser_name ); - // this is to pull out specific webkit versions, safari, google-chrome etc.. - $j_count = count( $a_webkit_types ); - for ( $j = 0; $j < $j_count; $j++ ) - { - if ( strstr( $browser_user_agent, $a_webkit_types[$j] ) ) - { - $webkit_type = $a_webkit_types[$j]; - /* - and this is the webkit type version number, like: chrome 1.2 - if omni web, we want the count 2, not default 1 - */ - if ( $webkit_type == 'omniweb' ) - { - G::get_set_count( 'set', 2 ); - } - $webkit_type_number = G::get_item_version( $browser_user_agent, $webkit_type ); - // epiphany hack - if ( $a_webkit_types[$j] == 'gtklauncher' ) - { - $browser_name = 'epiphany'; - } - else - { - $browser_name = $a_webkit_types[$j]; - } - break; - } - } - break; - default: - $browser_number = G::get_item_version( $browser_user_agent, $browser_name ); - break; - } - // the browser was id'ed - $b_success = true; - break; - } - } - - //assigns defaults if the browser was not found in the loop test - if ( !$b_success ) - { - /* - 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 - $browser_name = substr( $browser_user_agent, 0, strcspn( $browser_user_agent , '();') ); - // this extracts just the browser name from the string, if something usable was found - if ( $browser_name && preg_match( '/[^0-9][a-z]*-*\ *[a-z]*\ *[a-z]*/', $browser_name, $a_unhandled_browser ) ) - { - $browser_name = $a_unhandled_browser[0]; - - if ( $browser_name == 'blackberry' ) - { - G::get_set_count( 'set', 0 ); - } - $browser_number = G::get_item_version( $browser_user_agent, $browser_name ); - } - else - { - $browser_name = 'NA'; - $browser_number = 'NA'; - } - - // then uncomment this part - //$browser_name = '';//deletes the last array item in case the browser was not a match - } - // get os data, mac os x test requires browser/version information, this is a change from older scripts - if ( $b_os_test ) - { - $a_os_data = G::get_os_data( $browser_user_agent, $browser_working, $browser_number ); - $os_type = $a_os_data[0];// os name, abbreviated - $os_number = $a_os_data[1];// os number or version if available - } - /* - this ends the run through once if clause, set the boolean - to true so the function won't retest everything - */ - $b_repeat = true; - /* - pulls out primary version number from more complex string, like 7.5a, - use this for numeric version comparison - */ - if ( $browser_number && preg_match( '/[0-9]*\.*[0-9]*/', $browser_number, $a_browser_math_number ) ) - { - $browser_math_number = $a_browser_math_number[0]; - //print_r($a_browser_math_number); - } - 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 ); - $ua_type = 'mobile'; - } - } - } - //$browser_number = $_SERVER["REMOTE_ADDR"]; - /* - This is where you return values based on what parameter you used to call the function - $which_test is the passed parameter in the initial browser_detection('os') for example returns - the os version only. - - Update deprecated parameter names to new names - */ - 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 ) - { - $a_moz_data = array( $moz_type, $moz_number, $moz_rv, $moz_rv_full, $moz_release_date ); - } - if ( !$a_webkit_data ) - { - $a_webkit_data = array( $webkit_type, $webkit_type_number, $browser_number ); - } - $run_time = G::script_time(); - // then pack the primary data array - if ( !$a_full_assoc_data ) - { - $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 - ); - // print_r( $a_full_data ); - return $a_full_data; - break; - // returns all relevant browser information in an associative array - 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 - if ( isset( $a_full_assoc_data[$which_test] ) ) - { - return $a_full_assoc_data[$which_test]; - } - else - { - die( "You passed the browser detector an unsupported option for parameter 1: " . $which_test ); - } - break; - } -} - -// gets which os from the browser string -function get_os_data ( $pv_browser_string, $pv_browser_name, $pv_version_number ) -{ - // 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 - */ - $a_mac = array( 'intel mac', 'ppc mac', 'mac68k' );// this is not used currently - // same logic, check in order to catch the os's in order, last is always default item - $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' ); - // only sometimes will you get a linux distro to id itself... - $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 - // note, order of os very important in os array, you will get failed ids if changed - $a_os_types = array( 'android', 'blackberry', 'iphone', 'palmos', 'palmsource', 'symbian', 'beos', 'os2', 'amiga', 'webtv', 'mac', 'nt', 'win', $a_unix_types, $a_linux_distros ); - - //os tester - $i_count = count( $a_os_types ); - 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 - */ - if ( !is_array( $os_working_data ) && strstr( $pv_browser_string, $os_working_data ) && !strstr( $pv_browser_string, "linux" ) ) - { - $os_working_type = $os_working_data; - - switch ( $os_working_type ) - { - // most windows now uses: NT X.Y syntax - case 'nt': - if ( strstr( $pv_browser_string, 'nt 6.1' ) )// windows 7 - { - $os_working_number = 6.1; - } - elseif ( strstr( $pv_browser_string, 'nt 6.0' ) )// windows vista/server 2008 - { - $os_working_number = 6.0; - } - elseif ( strstr( $pv_browser_string, 'nt 5.2' ) )// windows server 2003 - { - $os_working_number = 5.2; - } - elseif ( strstr( $pv_browser_string, 'nt 5.1' ) || strstr( $pv_browser_string, 'xp' ) )// windows xp - { - $os_working_number = 5.1;// - } - elseif ( strstr( $pv_browser_string, 'nt 5' ) || strstr( $pv_browser_string, '2000' ) )// windows 2000 - { - $os_working_number = 5.0; - } - elseif ( strstr( $pv_browser_string, 'nt 4' ) )// nt 4 - { - $os_working_number = 4; - } - elseif ( strstr( $pv_browser_string, 'nt 3' ) )// nt 4 - { - $os_working_number = 3; - } - break; - case 'win': - if ( strstr( $pv_browser_string, 'vista' ) )// windows vista, for opera ID - { - $os_working_number = 6.0; - $os_working_type = 'nt'; - } - elseif ( strstr( $pv_browser_string, 'xp' ) )// windows xp, for opera ID - { - $os_working_number = 5.1; - $os_working_type = 'nt'; - } - elseif ( strstr( $pv_browser_string, '2003' ) )// windows server 2003, for opera ID - { - $os_working_number = 5.2; - $os_working_type = 'nt'; - } - elseif ( strstr( $pv_browser_string, 'windows ce' ) )// windows CE - { - $os_working_number = 'ce'; - $os_working_type = 'nt'; - } - elseif ( strstr( $pv_browser_string, '95' ) ) - { - $os_working_number = '95'; - } - elseif ( ( strstr( $pv_browser_string, '9x 4.9' ) ) || ( strstr( $pv_browser_string, ' me' ) ) ) - { - $os_working_number = 'me'; - } - elseif ( strstr( $pv_browser_string, '98' ) ) - { - $os_working_number = '98'; - } - elseif ( strstr( $pv_browser_string, '2000' ) )// windows 2000, for opera ID - { - $os_working_number = 5.0; - $os_working_type = 'nt'; - } - break; - case 'mac': - if ( strstr( $pv_browser_string, 'os x' ) ) - { - // if it doesn't have a version number, it is os x; - if ( strstr( $pv_browser_string, 'os x ' ) ) - { - // numbers are like: 10_2.4, others 10.2.4 - $os_working_number = str_replace( '_', '.', G::get_item_version( $pv_browser_string, 'os x' ) ); - } - else - { - $os_working_number = 10; - } - } - /* - this is a crude test for os x, since safari, camino, ie 5.2, & moz >= rv 1.3 - are only made for os x - */ - 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 ) ) ) - { - $os_working_number = 10; - } - break; - case 'iphone': - $os_working_number = 10; - break; - default: - break; - } - break; - } - /* - check that it's an array, check it's the second to last item - in the main os array, the unix one that is - */ - elseif ( is_array( $os_working_data ) && ( $i == ( $i_count - 2 ) ) ) - { - $j_count = count($os_working_data); - for ($j = 0; $j < $j_count; $j++) - { - if ( strstr( $pv_browser_string, $os_working_data[$j] ) ) - { - $os_working_type = 'unix'; //if the os is in the unix array, it's unix, obviously... - $os_working_number = ( $os_working_data[$j] != 'unix' ) ? $os_working_data[$j] : '';// assign sub unix version from the unix array - break; - } - } - } - /* - check that it's an array, check it's the last item - in the main os array, the linux one that is - */ - elseif ( is_array( $os_working_data ) && ( $i == ( $i_count - 1 ) ) ) - { - $j_count = count($os_working_data); - for ($j = 0; $j < $j_count; $j++) - { - if ( strstr( $pv_browser_string, $os_working_data[$j] ) ) - { - $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 '' - $os_working_number = ( $os_working_data[$j] != 'linux' ) ? $os_working_data[$j] : ''; - break; - } - } - } - } - - // pack the os data array for return to main function - $a_os_data = array( $os_working_type, $os_working_number ); - - return $a_os_data; -} - -/* -Function Info: -function returns browser number, gecko rv number, or gecko release date -function get_item_version( $browser_user_agent, $search_string, $substring_length ) -$pv_extra_search='' allows us to set an additional search/exit loop parameter, but we -only want this running when needed -*/ -function get_item_version( $pv_browser_user_agent, $pv_search_string, $pv_b_break_last='', $pv_extra_search='' ) -{ - // 12 is the longest that will be required, handles release dates: 20020323; 0.8.0+ - $substring_length = 15; - $start_pos = 0; // set $start_pos to 0 for first iteration - //initialize browser number, will return '' if not found - $string_working_number = ''; - /* - use the passed parameter for $pv_search_string - start the substring slice right after these moz search strings - there are some cases of double msie id's, first in string and then with then number - $start_pos = 0; - this test covers you for multiple occurrences of string, only with ie though - with for example google bot you want the first occurance returned, since that's where the - numbering happens - */ - for ( $i = 0; $i < 4; $i++ ) - { - //start the search after the first string occurrence - if ( strpos( $pv_browser_user_agent, $pv_search_string, $start_pos ) !== false ) - { - // update start position if position found - $start_pos = strpos( $pv_browser_user_agent, $pv_search_string, $start_pos ) + strlen( $pv_search_string ); - /* - msie (and maybe other userAgents requires special handling because some apps inject - a second msie, usually at the beginning, custom modes allow breaking at first instance - if $pv_b_break_last $pv_extra_search conditions exist. Since we only want this test - to run if and only if we need it, it's triggered by caller passing these values. - */ - if ( !$pv_b_break_last || ( $pv_extra_search && strstr( $pv_browser_user_agent, $pv_extra_search ) ) ) - { - break; - } - } - else - { - break; - } - } - /* - Handles things like extra omniweb/v456, gecko/, blackberry9700 - also corrects for the omniweb 'v' - */ - $start_pos += G::get_set_count( 'get' ); - $string_working_number = substr( $pv_browser_user_agent, $start_pos, $substring_length ); - - // Find the space, ;, or parentheses that ends the number - $string_working_number = substr( $string_working_number, 0, strcspn($string_working_number, ' );/') ); - - //make sure the returned value is actually the id number and not a string - // otherwise return '' - // strcspn( $string_working_number, '0123456789.') == strlen( $string_working_number) - // if ( preg_match("/\\d/", $string_working_number) == 0 ) - if ( !is_numeric( substr( $string_working_number, 0, 1 ) ) ) - { - $string_working_number = ''; - } - //$string_working_number = strrpos( $pv_browser_user_agent, $pv_search_string ); - return $string_working_number; -} - -function get_set_count( $pv_type, $pv_value='' ) -{ - static $slice_increment; - $return_value = ''; - switch ( $pv_type ) - { - case 'get': - // set if unset, ie, first use. note that empty and isset are not good tests here - if ( is_null( $slice_increment ) ) - { - $slice_increment = 1; - } - $return_value = $slice_increment; - $slice_increment = 1; // reset to default - return $return_value; - break; - case 'set': - $slice_increment = $pv_value; - break; - } -} - -/* -Special ID notes: -Novarra-Vision is a Content Transformation Server (CTS) -*/ -function check_is_mobile( $pv_browser_user_agent ) -{ - $mobile_working_test = ''; - /* - these will search for basic mobile hints, this should catch most of them, first check - known hand held device os, then check device names, then mobile browser names - This list is almost the same but not exactly as the 4 arrays in function below - */ - $a_mobile_search = array( - /* - Make sure to use only data here that always will be a mobile, so this list is not - identical to the list of get_mobile_data - */ - // os - '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 - 'avantgo', 'blazer', 'elaine', 'eudoraweb', 'iemobile', 'minimo', 'mobile safari', 'mobileexplorer', 'opera mobi', 'opera mini', 'netfront', 'opwv', 'polaris', 'semc-browser', 'up.browser', 'webpro', 'wms pie', 'xiino', - // services - astel out of business - 'astel', 'docomo', 'novarra-vision', 'portalmmm', 'reqwirelessweb', 'vodafone' - ); - - // then do basic mobile type search, this uses data from: get_mobile_data() - $j_count = count( $a_mobile_search ); - for ($j = 0; $j < $j_count; $j++) - { - if ( strstr( $pv_browser_user_agent, $a_mobile_search[$j] ) ) - { - $mobile_working_test = $a_mobile_search[$j]; - break; - } - } - - return $mobile_working_test; -} - -/* -thanks to this page: http://www.zytrax.com/tech/web/mobile_ids.html -for data used here -*/ -function get_mobile_data( $pv_browser_user_agent ) -{ - $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 = ''; - - // browsers, show it as a handheld, but is not the os - $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' ); - /* - This goes from easiest to detect to hardest, so don't use this for output unless you - clean it up more is my advice. - Special Notes: do not include milestone in general mobile type test above, it's too generic - */ - $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' ); - /* - note: linux alone can't be searched for, and almost all linux devices are armv types - ipad 'cpu os' is how the real os number is handled - */ - $a_mobile_os = array( 'android', 'epoc', 'cpu os', 'iphone os', 'palmos', 'palmsource', 'windows phone os', 'windows ce', 'symbianos', 'symbian os', 'symbian', 'webos', 'linux armv' ); - - // sometimes there is just no other id for the unit that the CTS type service/server - $a_mobile_server = array( 'astel', 'docomo', 'novarra-vision', 'portalmmm', 'reqwirelessweb', 'vodafone' ); - - $k_count = count( $a_mobile_browser ); - for ( $k = 0; $k < $k_count; $k++ ) - { - if ( strstr( $pv_browser_user_agent, $a_mobile_browser[$k] ) ) - { - $mobile_browser = $a_mobile_browser[$k]; - // this may or may not work, highly unreliable because mobile ua strings are random - $mobile_browser_number = G::get_item_version( $pv_browser_user_agent, $mobile_browser ); - break; - } - } - $k_count = count( $a_mobile_device ); - for ( $k = 0; $k < $k_count; $k++ ) - { - if ( strstr( $pv_browser_user_agent, $a_mobile_device[$k] ) ) - { - $mobile_device = trim ( $a_mobile_device[$k], '-_' ); // but not space trims yet - if ( $mobile_device == 'blackberry' ) - { - G::get_set_count( 'set', 0 ); - } - $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 - break; - } - } - $k_count = count( $a_mobile_os ); - for ( $k = 0; $k < $k_count; $k++ ) - { - if ( strstr( $pv_browser_user_agent, $a_mobile_os[$k] ) ) - { - $mobile_os = $a_mobile_os[$k]; - // this may or may not work, highly unreliable - $mobile_os_number = str_replace( '_', '.', G::get_item_version( $pv_browser_user_agent, $mobile_os ) ); - break; - } - } - $k_count = count( $a_mobile_server ); - for ( $k = 0; $k < $k_count; $k++ ) - { - if ( strstr( $pv_browser_user_agent, $a_mobile_server[$k] ) ) - { - $mobile_server = $a_mobile_server[$k]; - // this may or may not work, highly unreliable - $mobile_server_number = G::get_item_version( $pv_browser_user_agent, $mobile_server ); - break; - } - } - // just for cases where we know it's a mobile device already - if ( !$mobile_os && ( $mobile_browser || $mobile_device || $mobile_server ) && strstr( $pv_browser_user_agent, 'linux' ) ) - { - $mobile_os = 'linux'; - $mobile_os_number = G::get_item_version( $pv_browser_user_agent, 'linux' ); - } - - $a_mobile_data = array( $mobile_device, $mobile_browser, $mobile_browser_number, $mobile_os, $mobile_os_number, $mobile_server, $mobile_server_number, $mobile_device_number ); - return $a_mobile_data; -} - + } + + /** + * Validate and emai address in complete forms, + * + * @author Erik A.O. + * i.e. if the param. is 'erik a.o. ' + * -> returns a object within $o->email => erik@colosa.com and $o->name => erik A.O. in other case returns false + * + */ + function emailAddress($sEmail){ + $o = new stdClass(); + + if( strpos($sEmail, '<') !== false ) { + preg_match('/([\"\w@\.-_\s]*\s*)?(<(\w+[\.-]?\w+]*@\w+([\.-]?\w+)*\.\w{2,3})+>)/', $sEmail, $matches); + + if( isset($matches[1]) && $matches[3]){ + $o->email = $matches[3]; + $o->name = $matches[1]; + + return $o; + } + + return false; + } + else { + preg_match('/\w+[\.-]?\w+]*@\w+([\.-]?\w+)*\.\w{2,3}+/', $sEmail, $matches); + if( isset($matches[0]) ){ + $o->email = $matches[0]; + $o->name = ''; + return $o; + } + + return false; + } + } + + /** + * JSON encode + * + * @author Erik A.O. + */ + function json_encode($Json){ + if( function_exists('json_encode') ){ + return json_encode($Json); + } else { + G::LoadThirdParty('pear/json', 'class.json'); + $oJSON = new Services_JSON(); + return $oJSON->encode($Json); + } + } + + /** + * JSON decode + * + * @author Erik A.O. + */ + function json_decode($Json){ + if( function_exists('json_decode') ){ + return json_decode($Json); + } else { + G::LoadThirdParty('pear/json', 'class.json'); + $oJSON = new Services_JSON(); + return $oJSON->decode($Json); + } + } + + /** + * isHttpRequest + * + * @return boolean true or false + */ + function isHttpRequest(){ + 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 + * @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 ') + * array('to'=>array('email1', 'some name '), '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 + */ + function sendMail($from, $fromName, $address, $subject, $body) + { + // require_once "classes/class.pmFunctions.php"; + G::LoadClass("pmFunctions"); + G::LoadThirdParty('phpmailer', 'class.phpmailer'); + $setup = getEmailConfiguration(); + + 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'); + } + + $passwd = $setup['MESS_PASSWORD']; + $passwdDec = G::decrypt($passwd,'EMAILENCRYPT'); + $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; + $mail->IsHTML (true); + $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) { + $mail->AddBCC($emails[0], $emails[1]); + } + + return $mail->Send() ? true : $mail->ErrorInfo; + } + + /** + * Envelope a emails collection from a string or array + * @author Erik Amaru Ortiz + * @param mixed $address the possibles values are: + * string + * array('email1', 'some name ') + * array('to'=>array('email1', 'some name '), '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', ...) + * ) + */ + function envelopEmailAddresses($address) + { + $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. + * @return (string) type of variable + */ + public function gettype($var) { + switch ($var) { + case is_null($var): + $type='NULL'; + break; + + case is_bool($var): + $type='boolean'; + break; + + case is_float($var): + $type='double'; + break; + + case is_int($var): + $type='integer'; + break; + + case is_string($var): + $type='string'; + break; + + case is_array($var): + $type='array'; + break; + + case is_object($var): + $type='object'; + break; + + case is_resource($var): + $type='resource'; + break; + + default: + $type='unknown type'; + break; + } + + return $type; + } + + 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; + } + + function getMemoryUsage(){ + $size = memory_get_usage(true); + $unit=array('B','Kb','Mb','Gb','Tb','Pb'); + return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; + } + + function getFormatUserList($format, $aUserInfo){ + + 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; + } + + function getModel($model){ + require_once "classes/model/$model.php"; + return new $model(); + } + + /** + * Recursive Is writeable function + * + * @author Erik Amaru Ortiz + * + * @param $path path to scan recursively the write permission + * @param $pattern pattern to filter some especified files + * @return if the $path, assuming that is a directory -> all files in it are writeables or not + */ + function is_rwritable($path, $pattern='*') + { + $files = G::rglob($pattern, 0, $path); + foreach ($files as $file) { + if( ! is_writable($file) ) + return false; + } + return true; + } + + /** + * Recursive version of glob php standard function + * + * @author Erik Amaru Ortiz + * + * @param $path path to scan recursively the write permission + * @param $flags to notive glob function + * @param $pattern pattern to filter some especified files + * @return array containing the recursive glob results + */ + function rglob($pattern='*', $flags = 0, $path='') + { + $paths = glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT); + $files = glob($path.$pattern, $flags); + foreach ($paths as $path) { + $files = array_merge($files, G::rglob($pattern, $flags, $path)); + } + return $files; + } +function browser_detection( $which_test, $test_excludes='', $external_ua_string='' ) +{ + /* + uncomment the global variable declaration if you want the variables to be available on + a global level throughout your php page, make sure that php is configured to support + the use of globals first! + Use of globals should be avoided however, and they are not necessary with this script + /* + /* + global $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; + */ + 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. + if ( $external_ua_string ) + { + $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 + */ + if ( !$b_repeat ) + { + //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; + $b_success = false;// boolean for if browser found in main test + $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 = ''; + $ua_type = 'bot';// default to bot since you never know with bots + $webkit_type = ''; + $webkit_type_number = ''; + + // set the excludes if required + if ( $test_excludes ) + { + switch ( $test_excludes ) + { + 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: + die( 'Error: bad $test_excludes parameter 2 used: ' . $test_excludes ); + 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. + */ + 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'] ); + } + else + { + $browser_user_agent = ''; + } + + /* + pack the browser type array, in this order + the order is important, because opera must be tested first, then omniweb [which has safari + data in string], same for konqueror, then safari, then gecko, since safari navigator user + agent id's with 'gecko' in string. + Note that $b_dom_browser is set for all modern dom browsers, this gives you a default to use. + + array[0] = id string for useragent, array[1] is if dom capable, array[2] is working name + for browser, array[3] identifies navigator useragent type + + Note: all browser strings are in lower case to match the strtolower output, this avoids + possible detection errors + + Note: These are the navigator user agent types: + bro - modern, css supporting browser. + bbro - basic browser, text only, table only, defective css implementation + bot - search type spider + dow - known download agent + lib - standard http libraries + mobile - handheld or mobile browser, set using $mobile_test + */ + // known browsers, list will be updated routinely, check back now and then + $a_browser_types = array( + array( 'opera', true, 'op', 'bro' ), + array( 'msie', true, 'ie', 'bro' ), + // webkit before gecko because some webkit ua strings say: like gecko + array( 'webkit', true, 'webkit', 'bro' ), + // konq will be using webkit soon + array( 'konqueror', true, 'konq', 'bro' ), + // covers Netscape 6-7, K-Meleon, Most linux versions, uses moz array below + 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 + + // search engine spider bots: + 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' ), + + // various http utility libaries + 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' ), + + // download apps + array( 'getright', false, 'getright', 'dow' ), + array( 'wget', false, 'wget', 'dow' ),// open source downloader, obeys robots.txt + + // netscape 4 and earlier tests, put last so spiders don't get caught + array( 'mozilla/4.', false, 'ns', 'bbro' ), + array( 'mozilla/3.', false, 'ns', 'bbro' ), + array( 'mozilla/2.', false, 'ns', 'bbro' ) + ); + + //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 + */ + $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' ); + + /* + 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. + */ + $a_webkit_types = array( 'arora', 'chrome', 'epiphany', 'gtklauncher', 'konqueror', 'midori', 'omniweb', 'safari', 'uzbl', 'applewebkit', 'webkit' ); + + /* + 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. + */ + $i_count = count( $a_browser_types ); + for ( $i = 0; $i < $i_count; $i++ ) + { + //unpacks browser array, assigns to variables, need to not assign til found in string + $browser_temp = $a_browser_types[$i][0];// text string to id browser from array + + if ( strstr( $browser_user_agent, $browser_temp ) ) + { + /* + 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; + $browser_name = $browser_temp;// text string to id browser from array + + // assign values based on match of user agent string + $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 + + switch ( $browser_working ) + { + // 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; + $browser_number = G::get_item_version( $browser_user_agent, 'mozilla' ); + 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 + $moz_rv_full = G::get_item_version( $browser_user_agent, 'rv' ); + // this slices them back off for math comparisons + $moz_rv = substr( $moz_rv_full, 0, 3 ); + + // this is to pull out specific mozilla versions, firebird, netscape etc.. + $j_count = count( $a_moz_types ); + for ( $j = 0; $j < $j_count; $j++ ) + { + if ( strstr( $browser_user_agent, $a_moz_types[$j] ) ) + { + $moz_type = $a_moz_types[$j]; + $moz_number = G::get_item_version( $browser_user_agent, $moz_type ); + 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 + */ + if ( !$moz_rv ) + { + // you can use this if you are running php >= 4.2 + if ( function_exists( 'floatval' ) ) + { + $moz_rv = floatval( $moz_number ); + } + else + { + $moz_rv = substr( $moz_number, 0, 3 ); + } + $moz_rv_full = $moz_number; + } + // this corrects the version name in case it went to the default 'rv' for the test + if ( $moz_type == 'rv' ) + { + $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 + G::get_set_count( 'set', 0 ); + $moz_release_date = G::get_item_version( $browser_user_agent, 'gecko/' ); + /* + 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; + */ + if ( ( $moz_release_date < 20020400 ) || ( $moz_rv < 1 ) ) + { + $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/ + */ + $browser_number = G::get_item_version( $browser_user_agent, $browser_name, true, 'trident/' ); + // construct the proper real number if it's in compat mode and msie 8.0/9.0 + if ( strstr( $browser_number, '7.' ) && strstr( $browser_user_agent, 'trident/5' ) ) + { + // 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; + } + elseif ( strstr( $browser_number, '7.' ) && strstr( $browser_user_agent, 'trident/4' ) ) + { + // 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 + if ( $browser_number >= 9 ) + { + $ie_version = 'ie9x'; + } + // 7/8 were not yet quite to standards levels but getting there + elseif ( $browser_number >= 7 ) + { + $ie_version = 'ie7x'; + } + // then test for IE 5x mac, that's the most problematic IE out there + elseif ( strstr( $browser_user_agent, 'mac') ) + { + $ie_version = 'ieMac'; + } + // ie 5/6 are both very weak in standards compliance + elseif ( $browser_number >= 5 ) + { + $ie_version = 'ie5x'; + } + elseif ( ( $browser_number > 3 ) && ( $browser_number < 5 ) ) + { + $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': + $browser_number = G::get_item_version( $browser_user_agent, $browser_name ); + // 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/ + 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/' ); + } + + if ( $browser_number < 5 )// opera 4 wasn't very useable. + { + $b_safe_browser = false; + } + break; + /* + note: webkit returns always the webkit version number, not the specific user + agent version, ie, webkit 583, not chrome 0.3 + */ + case 'webkit': + // note that this is the Webkit version number + $browser_number = G::get_item_version( $browser_user_agent, $browser_name ); + // this is to pull out specific webkit versions, safari, google-chrome etc.. + $j_count = count( $a_webkit_types ); + for ( $j = 0; $j < $j_count; $j++ ) + { + if ( strstr( $browser_user_agent, $a_webkit_types[$j] ) ) + { + $webkit_type = $a_webkit_types[$j]; + /* + and this is the webkit type version number, like: chrome 1.2 + if omni web, we want the count 2, not default 1 + */ + if ( $webkit_type == 'omniweb' ) + { + G::get_set_count( 'set', 2 ); + } + $webkit_type_number = G::get_item_version( $browser_user_agent, $webkit_type ); + // epiphany hack + if ( $a_webkit_types[$j] == 'gtklauncher' ) + { + $browser_name = 'epiphany'; + } + else + { + $browser_name = $a_webkit_types[$j]; + } + break; + } + } + break; + default: + $browser_number = G::get_item_version( $browser_user_agent, $browser_name ); + break; + } + // the browser was id'ed + $b_success = true; + break; + } + } + + //assigns defaults if the browser was not found in the loop test + if ( !$b_success ) + { + /* + 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 + $browser_name = substr( $browser_user_agent, 0, strcspn( $browser_user_agent , '();') ); + // this extracts just the browser name from the string, if something usable was found + if ( $browser_name && preg_match( '/[^0-9][a-z]*-*\ *[a-z]*\ *[a-z]*/', $browser_name, $a_unhandled_browser ) ) + { + $browser_name = $a_unhandled_browser[0]; + + if ( $browser_name == 'blackberry' ) + { + G::get_set_count( 'set', 0 ); + } + $browser_number = G::get_item_version( $browser_user_agent, $browser_name ); + } + else + { + $browser_name = 'NA'; + $browser_number = 'NA'; + } + + // then uncomment this part + //$browser_name = '';//deletes the last array item in case the browser was not a match + } + // get os data, mac os x test requires browser/version information, this is a change from older scripts + if ( $b_os_test ) + { + $a_os_data = G::get_os_data( $browser_user_agent, $browser_working, $browser_number ); + $os_type = $a_os_data[0];// os name, abbreviated + $os_number = $a_os_data[1];// os number or version if available + } + /* + this ends the run through once if clause, set the boolean + to true so the function won't retest everything + */ + $b_repeat = true; + /* + pulls out primary version number from more complex string, like 7.5a, + use this for numeric version comparison + */ + if ( $browser_number && preg_match( '/[0-9]*\.*[0-9]*/', $browser_number, $a_browser_math_number ) ) + { + $browser_math_number = $a_browser_math_number[0]; + //print_r($a_browser_math_number); + } + 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 ); + $ua_type = 'mobile'; + } + } + } + //$browser_number = $_SERVER["REMOTE_ADDR"]; + /* + This is where you return values based on what parameter you used to call the function + $which_test is the passed parameter in the initial browser_detection('os') for example returns + the os version only. + + Update deprecated parameter names to new names + */ + 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 ) + { + $a_moz_data = array( $moz_type, $moz_number, $moz_rv, $moz_rv_full, $moz_release_date ); + } + if ( !$a_webkit_data ) + { + $a_webkit_data = array( $webkit_type, $webkit_type_number, $browser_number ); + } + $run_time = G::script_time(); + // then pack the primary data array + if ( !$a_full_assoc_data ) + { + $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 + ); + // print_r( $a_full_data ); + return $a_full_data; + break; + // returns all relevant browser information in an associative array + 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 + if ( isset( $a_full_assoc_data[$which_test] ) ) + { + return $a_full_assoc_data[$which_test]; + } + else + { + die( "You passed the browser detector an unsupported option for parameter 1: " . $which_test ); + } + break; + } +} + +// gets which os from the browser string +function get_os_data ( $pv_browser_string, $pv_browser_name, $pv_version_number ) +{ + // 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 + */ + $a_mac = array( 'intel mac', 'ppc mac', 'mac68k' );// this is not used currently + // same logic, check in order to catch the os's in order, last is always default item + $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' ); + // only sometimes will you get a linux distro to id itself... + $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 + // note, order of os very important in os array, you will get failed ids if changed + $a_os_types = array( 'android', 'blackberry', 'iphone', 'palmos', 'palmsource', 'symbian', 'beos', 'os2', 'amiga', 'webtv', 'mac', 'nt', 'win', $a_unix_types, $a_linux_distros ); + + //os tester + $i_count = count( $a_os_types ); + 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 + */ + if ( !is_array( $os_working_data ) && strstr( $pv_browser_string, $os_working_data ) && !strstr( $pv_browser_string, "linux" ) ) + { + $os_working_type = $os_working_data; + + switch ( $os_working_type ) + { + // most windows now uses: NT X.Y syntax + case 'nt': + if ( strstr( $pv_browser_string, 'nt 6.1' ) )// windows 7 + { + $os_working_number = 6.1; + } + elseif ( strstr( $pv_browser_string, 'nt 6.0' ) )// windows vista/server 2008 + { + $os_working_number = 6.0; + } + elseif ( strstr( $pv_browser_string, 'nt 5.2' ) )// windows server 2003 + { + $os_working_number = 5.2; + } + elseif ( strstr( $pv_browser_string, 'nt 5.1' ) || strstr( $pv_browser_string, 'xp' ) )// windows xp + { + $os_working_number = 5.1;// + } + elseif ( strstr( $pv_browser_string, 'nt 5' ) || strstr( $pv_browser_string, '2000' ) )// windows 2000 + { + $os_working_number = 5.0; + } + elseif ( strstr( $pv_browser_string, 'nt 4' ) )// nt 4 + { + $os_working_number = 4; + } + elseif ( strstr( $pv_browser_string, 'nt 3' ) )// nt 4 + { + $os_working_number = 3; + } + break; + case 'win': + if ( strstr( $pv_browser_string, 'vista' ) )// windows vista, for opera ID + { + $os_working_number = 6.0; + $os_working_type = 'nt'; + } + elseif ( strstr( $pv_browser_string, 'xp' ) )// windows xp, for opera ID + { + $os_working_number = 5.1; + $os_working_type = 'nt'; + } + elseif ( strstr( $pv_browser_string, '2003' ) )// windows server 2003, for opera ID + { + $os_working_number = 5.2; + $os_working_type = 'nt'; + } + elseif ( strstr( $pv_browser_string, 'windows ce' ) )// windows CE + { + $os_working_number = 'ce'; + $os_working_type = 'nt'; + } + elseif ( strstr( $pv_browser_string, '95' ) ) + { + $os_working_number = '95'; + } + elseif ( ( strstr( $pv_browser_string, '9x 4.9' ) ) || ( strstr( $pv_browser_string, ' me' ) ) ) + { + $os_working_number = 'me'; + } + elseif ( strstr( $pv_browser_string, '98' ) ) + { + $os_working_number = '98'; + } + elseif ( strstr( $pv_browser_string, '2000' ) )// windows 2000, for opera ID + { + $os_working_number = 5.0; + $os_working_type = 'nt'; + } + break; + case 'mac': + if ( strstr( $pv_browser_string, 'os x' ) ) + { + // if it doesn't have a version number, it is os x; + if ( strstr( $pv_browser_string, 'os x ' ) ) + { + // numbers are like: 10_2.4, others 10.2.4 + $os_working_number = str_replace( '_', '.', G::get_item_version( $pv_browser_string, 'os x' ) ); + } + else + { + $os_working_number = 10; + } + } + /* + this is a crude test for os x, since safari, camino, ie 5.2, & moz >= rv 1.3 + are only made for os x + */ + 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 ) ) ) + { + $os_working_number = 10; + } + break; + case 'iphone': + $os_working_number = 10; + break; + default: + break; + } + break; + } + /* + check that it's an array, check it's the second to last item + in the main os array, the unix one that is + */ + elseif ( is_array( $os_working_data ) && ( $i == ( $i_count - 2 ) ) ) + { + $j_count = count($os_working_data); + for ($j = 0; $j < $j_count; $j++) + { + if ( strstr( $pv_browser_string, $os_working_data[$j] ) ) + { + $os_working_type = 'unix'; //if the os is in the unix array, it's unix, obviously... + $os_working_number = ( $os_working_data[$j] != 'unix' ) ? $os_working_data[$j] : '';// assign sub unix version from the unix array + break; + } + } + } + /* + check that it's an array, check it's the last item + in the main os array, the linux one that is + */ + elseif ( is_array( $os_working_data ) && ( $i == ( $i_count - 1 ) ) ) + { + $j_count = count($os_working_data); + for ($j = 0; $j < $j_count; $j++) + { + if ( strstr( $pv_browser_string, $os_working_data[$j] ) ) + { + $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 '' + $os_working_number = ( $os_working_data[$j] != 'linux' ) ? $os_working_data[$j] : ''; + break; + } + } + } + } + + // pack the os data array for return to main function + $a_os_data = array( $os_working_type, $os_working_number ); + + return $a_os_data; +} + +/* +Function Info: +function returns browser number, gecko rv number, or gecko release date +function get_item_version( $browser_user_agent, $search_string, $substring_length ) +$pv_extra_search='' allows us to set an additional search/exit loop parameter, but we +only want this running when needed +*/ +function get_item_version( $pv_browser_user_agent, $pv_search_string, $pv_b_break_last='', $pv_extra_search='' ) +{ + // 12 is the longest that will be required, handles release dates: 20020323; 0.8.0+ + $substring_length = 15; + $start_pos = 0; // set $start_pos to 0 for first iteration + //initialize browser number, will return '' if not found + $string_working_number = ''; + /* + use the passed parameter for $pv_search_string + start the substring slice right after these moz search strings + there are some cases of double msie id's, first in string and then with then number + $start_pos = 0; + this test covers you for multiple occurrences of string, only with ie though + with for example google bot you want the first occurance returned, since that's where the + numbering happens + */ + for ( $i = 0; $i < 4; $i++ ) + { + //start the search after the first string occurrence + if ( strpos( $pv_browser_user_agent, $pv_search_string, $start_pos ) !== false ) + { + // update start position if position found + $start_pos = strpos( $pv_browser_user_agent, $pv_search_string, $start_pos ) + strlen( $pv_search_string ); + /* + msie (and maybe other userAgents requires special handling because some apps inject + a second msie, usually at the beginning, custom modes allow breaking at first instance + if $pv_b_break_last $pv_extra_search conditions exist. Since we only want this test + to run if and only if we need it, it's triggered by caller passing these values. + */ + if ( !$pv_b_break_last || ( $pv_extra_search && strstr( $pv_browser_user_agent, $pv_extra_search ) ) ) + { + break; + } + } + else + { + break; + } + } + /* + Handles things like extra omniweb/v456, gecko/, blackberry9700 + also corrects for the omniweb 'v' + */ + $start_pos += G::get_set_count( 'get' ); + $string_working_number = substr( $pv_browser_user_agent, $start_pos, $substring_length ); + + // Find the space, ;, or parentheses that ends the number + $string_working_number = substr( $string_working_number, 0, strcspn($string_working_number, ' );/') ); + + //make sure the returned value is actually the id number and not a string + // otherwise return '' + // strcspn( $string_working_number, '0123456789.') == strlen( $string_working_number) + // if ( preg_match("/\\d/", $string_working_number) == 0 ) + if ( !is_numeric( substr( $string_working_number, 0, 1 ) ) ) + { + $string_working_number = ''; + } + //$string_working_number = strrpos( $pv_browser_user_agent, $pv_search_string ); + return $string_working_number; +} + +function get_set_count( $pv_type, $pv_value='' ) +{ + static $slice_increment; + $return_value = ''; + switch ( $pv_type ) + { + case 'get': + // set if unset, ie, first use. note that empty and isset are not good tests here + if ( is_null( $slice_increment ) ) + { + $slice_increment = 1; + } + $return_value = $slice_increment; + $slice_increment = 1; // reset to default + return $return_value; + break; + case 'set': + $slice_increment = $pv_value; + break; + } +} + +/* +Special ID notes: +Novarra-Vision is a Content Transformation Server (CTS) +*/ +function check_is_mobile( $pv_browser_user_agent ) +{ + $mobile_working_test = ''; + /* + these will search for basic mobile hints, this should catch most of them, first check + known hand held device os, then check device names, then mobile browser names + This list is almost the same but not exactly as the 4 arrays in function below + */ + $a_mobile_search = array( + /* + Make sure to use only data here that always will be a mobile, so this list is not + identical to the list of get_mobile_data + */ + // os + '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 + 'avantgo', 'blazer', 'elaine', 'eudoraweb', 'iemobile', 'minimo', 'mobile safari', 'mobileexplorer', 'opera mobi', 'opera mini', 'netfront', 'opwv', 'polaris', 'semc-browser', 'up.browser', 'webpro', 'wms pie', 'xiino', + // services - astel out of business + 'astel', 'docomo', 'novarra-vision', 'portalmmm', 'reqwirelessweb', 'vodafone' + ); + + // then do basic mobile type search, this uses data from: get_mobile_data() + $j_count = count( $a_mobile_search ); + for ($j = 0; $j < $j_count; $j++) + { + if ( strstr( $pv_browser_user_agent, $a_mobile_search[$j] ) ) + { + $mobile_working_test = $a_mobile_search[$j]; + break; + } + } + + return $mobile_working_test; +} + +/* +thanks to this page: http://www.zytrax.com/tech/web/mobile_ids.html +for data used here +*/ +function get_mobile_data( $pv_browser_user_agent ) +{ + $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 = ''; + + // browsers, show it as a handheld, but is not the os + $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' ); + /* + This goes from easiest to detect to hardest, so don't use this for output unless you + clean it up more is my advice. + Special Notes: do not include milestone in general mobile type test above, it's too generic + */ + $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' ); + /* + note: linux alone can't be searched for, and almost all linux devices are armv types + ipad 'cpu os' is how the real os number is handled + */ + $a_mobile_os = array( 'android', 'epoc', 'cpu os', 'iphone os', 'palmos', 'palmsource', 'windows phone os', 'windows ce', 'symbianos', 'symbian os', 'symbian', 'webos', 'linux armv' ); + + // sometimes there is just no other id for the unit that the CTS type service/server + $a_mobile_server = array( 'astel', 'docomo', 'novarra-vision', 'portalmmm', 'reqwirelessweb', 'vodafone' ); + + $k_count = count( $a_mobile_browser ); + for ( $k = 0; $k < $k_count; $k++ ) + { + if ( strstr( $pv_browser_user_agent, $a_mobile_browser[$k] ) ) + { + $mobile_browser = $a_mobile_browser[$k]; + // this may or may not work, highly unreliable because mobile ua strings are random + $mobile_browser_number = G::get_item_version( $pv_browser_user_agent, $mobile_browser ); + break; + } + } + $k_count = count( $a_mobile_device ); + for ( $k = 0; $k < $k_count; $k++ ) + { + if ( strstr( $pv_browser_user_agent, $a_mobile_device[$k] ) ) + { + $mobile_device = trim ( $a_mobile_device[$k], '-_' ); // but not space trims yet + if ( $mobile_device == 'blackberry' ) + { + G::get_set_count( 'set', 0 ); + } + $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 + break; + } + } + $k_count = count( $a_mobile_os ); + for ( $k = 0; $k < $k_count; $k++ ) + { + if ( strstr( $pv_browser_user_agent, $a_mobile_os[$k] ) ) + { + $mobile_os = $a_mobile_os[$k]; + // this may or may not work, highly unreliable + $mobile_os_number = str_replace( '_', '.', G::get_item_version( $pv_browser_user_agent, $mobile_os ) ); + break; + } + } + $k_count = count( $a_mobile_server ); + for ( $k = 0; $k < $k_count; $k++ ) + { + if ( strstr( $pv_browser_user_agent, $a_mobile_server[$k] ) ) + { + $mobile_server = $a_mobile_server[$k]; + // this may or may not work, highly unreliable + $mobile_server_number = G::get_item_version( $pv_browser_user_agent, $mobile_server ); + break; + } + } + // just for cases where we know it's a mobile device already + if ( !$mobile_os && ( $mobile_browser || $mobile_device || $mobile_server ) && strstr( $pv_browser_user_agent, 'linux' ) ) + { + $mobile_os = 'linux'; + $mobile_os_number = G::get_item_version( $pv_browser_user_agent, 'linux' ); + } + + $a_mobile_data = array( $mobile_device, $mobile_browser, $mobile_browser_number, $mobile_os, $mobile_os_number, $mobile_server, $mobile_server_number, $mobile_device_number ); + return $a_mobile_data; +} + function getBrowser () { $u_agent = $_SERVER['HTTP_USER_AGENT']; @@ -4792,7 +4792,7 @@ function get_mobile_data( $pv_browser_user_agent ) $platform = 'Unknown'; $version = ""; - //First get the platform? + //First get the platform? if (preg_match( '/linux/i', $u_agent )) { $platform = 'linux'; } elseif (preg_match( '/macintosh|mac os x/i', $u_agent )) { @@ -4801,7 +4801,7 @@ function get_mobile_data( $pv_browser_user_agent ) $platform = 'windows'; } - // Next get the name of the useragent yes seperately and for good reason + // Next get the name of the useragent yes seperately and for good reason if (preg_match( '/MSIE/i', $u_agent ) && ! preg_match( '/Opera/i', $u_agent )) { $bname = 'Internet Explorer'; $ub = "MSIE"; @@ -4822,17 +4822,17 @@ function get_mobile_data( $pv_browser_user_agent ) $ub = "Netscape"; } - // finally get the correct version number + // finally get the correct version number $known = array ('Version',$ub,'other' ); $pattern = '#(?P' . join( '|', $known ) . ')[/ ]+(?P[0-9.|a-zA-Z.]*)#'; @preg_match_all( $pattern, $u_agent, $matches ); - // see how many we have + // see how many we have $i = count( $matches['browser'] ); if ($i != 1) { - //we will have two since we are not using 'other' argument yet - //see if version is before or after the name + //we will have two since we are not using 'other' argument yet + //see if version is before or after the name if (strripos( $u_agent, "Version" ) < strripos( $u_agent, $ub )) { $version = $matches['version'][0]; } else { @@ -4842,7 +4842,7 @@ function get_mobile_data( $pv_browser_user_agent ) $version = $matches['version'][0]; } - // check if we have a number + // check if we have a number if ($version == null || $version == "") { $version = "?"; } @@ -4851,23 +4851,23 @@ function get_mobile_data( $pv_browser_user_agent ) ); } - // track total script execution time + // track total script execution time function script_time () { static $script_time; $elapsed_time = ''; - /* - note that microtime(true) requires php 5 or greater for microtime(true) + /* + note that microtime(true) requires php 5 or greater for microtime(true) */ if (sprintf( "%01.1f", phpversion() ) >= 5) { if (is_null( $script_time )) { $script_time = microtime( true ); } else { - // note: (string)$var is same as strval($var) - // $elapsed_time = (string)( microtime(true) - $script_time ); + // note: (string)$var is same as strval($var) + // $elapsed_time = (string)( microtime(true) - $script_time ); $elapsed_time = (microtime( true ) - $script_time); $elapsed_time = sprintf( "%01.8f", $elapsed_time ); - $script_time = NULL; // can't unset a static variable + $script_time = NULL; // can't unset a static variable return $elapsed_time; } } @@ -4969,7 +4969,7 @@ function get_mobile_data( $pv_browser_user_agent ) $key = $match['key']; $value = $match['value']; - //Remove quote + //Remove quote if (preg_match( "/^\".*\"$/", $value ) || preg_match( "/^'.*'$/", $value )) { $value = mb_substr( $value, 1, mb_strlen( $value ) - 2 ); } @@ -5103,12 +5103,12 @@ function get_mobile_data( $pv_browser_user_agent ) $tplExists = true; - // file has absolute path + // file has absolute path if (substr( $template, 0, 1 ) != PATH_SEP) { $template = PATH_TEMPLATE . $template; } - // fix for template that have dot in its name but is not a valid extension + // fix for template that have dot in its name but is not a valid extension if (isset( $fInfo['extension'] ) && ($fInfo['extension'] != 'tpl' || $fInfo['extension'] != 'html')) { unset( $fInfo['extension'] ); } @@ -5213,7 +5213,7 @@ function get_mobile_data( $pv_browser_user_agent ) $iniLines[] = $line; } - // inserting new values + // inserting new values foreach ($array as $key => $value) { $line = "$key = " . (is_numeric( $value ) ? $value : '"' . $value . '"'); $iniLines[] = ''; @@ -5238,7 +5238,7 @@ function get_mobile_data( $pv_browser_user_agent ) * @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 */ - function is_writable_r ($path, &$noWritableFiles = array()) + function is_writable_r ($path, &$noWritableFiles = array()) { if (is_writable( $path )) { if (! is_dir( $path )) { @@ -5257,7 +5257,7 @@ function get_mobile_data( $pv_browser_user_agent ) } else { if (! in_array( $path, $noWritableFiles )) { $noWritableFiles[] = $path; - } + } return false; } } @@ -5273,7 +5273,7 @@ function get_mobile_data( $pv_browser_user_agent ) $rest = new Restler(); $rest->setSupportedFormats( 'JsonFormat', 'XmlFormat' ); - // getting all services class + // getting all services class $restClasses = array (); $restClassesList = G::rglob( '*', 0, PATH_CORE . 'services/' ); foreach ($restClassesList as $classFile) { @@ -5291,7 +5291,7 @@ function get_mobile_data( $pv_browser_user_agent ) } $restClasses = array_merge( $restClasses, $pluginRestClasses ); } - // hook to get rest api classes from plugins + // hook to get rest api classes from plugins if (class_exists( 'PMPluginRegistry' )) { $pluginRegistry = & PMPluginRegistry::getSingleton(); $pluginClasses = $pluginRegistry->getRegisteredRestClassFiles(); @@ -5302,34 +5302,34 @@ function get_mobile_data( $pv_browser_user_agent ) unset( $restClasses[$key] ); continue; } - //load the file, and check if exist the class inside it. + //load the file, and check if exist the class inside it. require_once $classFile; $namespace = 'Services_Rest_'; $className = str_replace( '.php', '', basename( $classFile ) ); - // if the core class does not exists try resolve the for a plugin + // if the core class does not exists try resolve the for a plugin if (! class_exists( $namespace . $className )) { $namespace = 'Plugin_Services_Rest_'; - // Couldn't resolve the class name, just skipp it + // Couldn't resolve the class name, just skipp it if (! class_exists( $namespace . $className )) { unset( $restClasses[$key] ); continue; } } - // verify if there is an auth class implementing 'iAuthenticate' + // verify if there is an auth class implementing 'iAuthenticate' $classNameAuth = $namespace . $className; $reflClass = new ReflectionClass( $classNameAuth ); - // that wasn't from plugin + // that wasn't from plugin if ($reflClass->implementsInterface( 'iAuthenticate' ) && $namespace != 'Plugin_Services_Rest_') { - // auth class found, set as restler authentication class handler + // auth class found, set as restler authentication class handler $rest->addAuthenticationClass( $classNameAuth ); } else { - // add api class + // add api class $rest->addAPIClass( $classNameAuth ); } } - //end foreach rest class - // resolving the class for current request + //end foreach rest class + // resolving the class for current request $uriPart = explode( '/', $uri ); $requestedClass = ''; if (isset( $uriPart[1] )) { @@ -5342,34 +5342,34 @@ function get_mobile_data( $pv_browser_user_agent ) } else { $namespace = ''; } - // end resolv. - // Send additional headers (if exists) configured on rest-config.ini + // end resolv. + // Send additional headers (if exists) configured on rest-config.ini if (array_key_exists( 'HEADERS', $config )) { foreach ($config['HEADERS'] as $name => $value) { header( "$name: $value" ); - } - } - // to handle a request with "OPTIONS" method - if (! empty( $namespace ) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') { - $reflClass = new ReflectionClass( $namespace . $requestedClass ); - // if the rest class has not a "options" method + } + } + // to handle a request with "OPTIONS" method + if (! empty( $namespace ) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') { + $reflClass = new ReflectionClass( $namespace . $requestedClass ); + // if the rest class has not a "options" method if (! $reflClass->hasMethod( 'options' )) { 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' ); + header( 'Access-Control-Allow-Headers: authorization, content-type' ); + header( "Access-Control-Allow-Credentials", "false" ); + header( 'Access-Control-Max-Age: 60' ); exit(); - } - } - // override global REQUEST_URI to pass to Restler library - $_SERVER['REQUEST_URI'] = '/' . strtolower( $namespace ) . ltrim( $uri, '/' ); - // handle the rest request + } + } + // override global REQUEST_URI to pass to Restler library + $_SERVER['REQUEST_URI'] = '/' . strtolower( $namespace ) . ltrim( $uri, '/' ); + // handle the rest request $rest->handle(); } public function reservedWordsSql () { - //Reserved words SQL + //Reserved words SQL $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", "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", @@ -5377,6 +5377,36 @@ function get_mobile_data( $pv_browser_user_agent ) "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. + * return true if the file exists, otherwise false. + */ + function isPMUnderUpdating($setFlag = 2) + { + $fileCheck = PATH_DATA."UPDATE.dat"; + if($setFlag == 0){ + if (file_exists($fileCheck)){ + unlink ($fileCheck); + } + } + else if($setFlag == 1){ + $fp = fopen($fileCheck,'w'); + $line = fputs($fp,"true"); + } + //checking temporary file + if($setFlag >= 1){ + if ( file_exists($fileCheck)){ + return true; + } + } + return false; + } } /** @@ -5393,7 +5423,7 @@ function eprint ($s = "", $c = null) if (isset( $c )) { echo "
$s
"; } else { - echo "
$s
"; + echo "
$s
"; } } else { if (isset( $c )) { @@ -5411,7 +5441,7 @@ function eprint ($s = "", $c = null) print "$s"; } } else { - print "$s"; + print "$s"; } } } @@ -5442,13 +5472,13 @@ function eprintln ($s = "", $c = null) if (isset( $c )) { echo "
$s
"; } else { - echo "
$s
"; + echo "
$s
"; } } else { if (isset( $c ) && (PHP_OS != 'WINNT')) { switch ($c) { case 'green': - printf( "\033[0;35;32m$s\033[0m\n" ); + printf( "\033[0;35;32m$s\033[0m\n" ); return; case 'red': printf( "\033[0;35;31m$s\033[0m\n" ); @@ -5465,5 +5495,5 @@ function eprintln ($s = "", $c = null) function __ ($msgID, $lang = SYS_LANG, $data = null) { return G::LoadTranslation( $msgID, $lang, $data ); -} - +} +
$type: $msg
$type: $msg
File: $file
$i
$i $str