Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class NE_Lib
- {
- public function NE_Lib()
- {
- exit( "Don't instantiate the NE_Lib class!" );
- }
- public function printR( $var, $terminate = FALSE )
- {
- echo "\n<pre>".print_r( $var, TRUE )."</pre>\n";
- if ( $terminate )
- {
- exit();
- }
- }
- public function getStack( $hidePaths )
- {
- $stack = debug_backtrace();
- array_shift( &$stack );
- $stackPretty = array();
- foreach ( $stack as $call )
- {
- if ( isset( $call['file'] ) )
- {
- if ( $hidePaths )
- {
- $call['file'] = mb_substr( $call['file'], strrpos( $call['file'], "\\" ) + 1 );
- }
- }
- else
- {
- $call['file'] = "no file";
- }
- $stackPretty[] = $call['file']." (".( isset( $call['line'] ) ? $call['line'] : "no line" ).") : ".( isset( $call['class'] ) ? $call['class']."::" : "" ).$call['function'];
- }
- return $stackPretty;
- }
- public function getStackCaller()
- {
- $info = array( "file" => "no file", "line" => "no line" );
- $level = 3;
- $stack = debug_backtrace();
- if ( isset( $stack[$level]['file'] ) )
- {
- $info['file'] = mb_substr( $stack[$level]['file'], strrpos( $stack[$level]['file'], "\\" ) + 1 );
- }
- if ( isset( $stack[$level]['line'] ) )
- {
- $info['line'] = $stack[$level]['line'];
- }
- return $info;
- }
- public function returnPopUpString( $strPopUpText, &$settings, $strURL = "", $tLink = "NONE", $extra = "", $isPublicView = FALSE )
- {
- if ( $strURL == "" )
- {
- $strURL = "javascript:void(0);";
- }
- $strPopUpText = preg_replace( "/\r\n|\n\r|\n|\r/", " ", $strPopUpText );
- $strPopUpText = str_replace( "'", "'", $strPopUpText );
- $strPopUpText = str_replace( "\"", """, $strPopUpText );
- $strPopUpText = htmlspecialchars( $strPopUpText, ENT_QUOTES );
- if ( $tLink == "NONE" )
- {
- $dir = NE_Lib::ispublicdir() ? "" : "../";
- $tLink = "<img src=\"".$dir.( "images/information-button.png\" alt='' qtip=\"".$strPopUpText."\" border=\"0\" style=\"position:relative; left:0px; top:2px\" />" );
- }
- $strReturnString = "<a href=\"".$strURL."\" qtip=\"{$strPopUpText}\" {$extra}>{$tLink}</a>";
- return $strReturnString;
- }
- public function getHighlight( $words, $haystack, $hs = "<font class=searchfound>", $he = "</font>" )
- {
- if ( is_array( $words ) )
- {
- foreach ( $words as $word )
- {
- $haystack = preg_replace( "|\\b(".quotemeta( $word ).")\\b|iU", $hs."\\1".$he, $haystack );
- }
- return $haystack;
- }
- $haystack = preg_replace( "|\\b(".quotemeta( $words ).")\\b|iU", $hs."\\1".$he, $haystack );
- return $haystack;
- }
- public function escapeHTMLAttributeValue( $st )
- {
- $st = str_replace( "\"", """, $st );
- return $st;
- }
- public function is_utf8( $str )
- {
- $c = 0;
- $b = 0;
- $bits = 0;
- $len = strlen( $str );
- $i = 0;
- for ( ; $i < $len; ++$i )
- {
- $c = ord( $str[$i] );
- if ( !( 128 < $c ) )
- {
- continue;
- }
- if ( 254 <= $c )
- {
- return FALSE;
- }
- if ( 252 <= $c )
- {
- $bits = 6;
- }
- else if ( 248 <= $c )
- {
- $bits = 5;
- }
- else if ( 240 <= $c )
- {
- $bits = 4;
- }
- else if ( 224 <= $c )
- {
- $bits = 3;
- }
- else if ( 192 <= $c )
- {
- $bits = 2;
- }
- else
- {
- return FALSE;
- }
- if ( $len < $i + $bits )
- {
- return FALSE;
- }
- while ( 1 < $bits )
- {
- ++$i;
- $b = ord( $str[$i] );
- if ( $b < 128 || 191 < $b )
- {
- return FALSE;
- }
- --$bits;
- }
- }
- return TRUE;
- }
- public function convToUtf8( $str )
- {
- if ( mb_detect_encoding( $str, "UTF-8, ISO-8859-1, GBK" ) != "UTF-8" )
- {
- return iconv( "gbk", "utf-8", $str );
- }
- return $str;
- }
- public function jsonencode( $a = FALSE )
- {
- try
- {
- if ( version_compare( phpversion(), "5.2.0", "<" ) )
- {
- require_once( "newedge/classes/Services/JSON.php" );
- ();
- $json = new Services_JSON();
- $ret = $json->encode( $a );
- return $ret;
- }
- $ret = json_encode( $a );
- return $ret;
- }
- catch ( Exception $ex )
- {
- $this->logger->log( 1, $ex->getMessage() );
- $this->logger->log( 1, $a );
- }
- }
- public function escapeJSON( $value )
- {
- $search = array( "\\", "\r\n", "\r", "\n", "\"", "/", "\\b", "\\f", "\t" );
- $replace = array( "\\\\", "\\r\\n", "\\r", "\\n", "\\\"", "\\/", "\\b", "\\f", "\\t" );
- return str_replace( $search, $replace, $value );
- }
- public function getAltColor( &$intColorIndex )
- {
- if ( $intColorIndex == 0 )
- {
- $strColor = "primarycolor";
- $intColorIndex = 1;
- return $strColor;
- }
- $strColor = "secondarycolor";
- $intColorIndex = 0;
- return $strColor;
- }
- public static function db_to_form( $date, $format, $delimiter = ".", $time = FALSE )
- {
- if ( $time )
- {
- $dateTime = explode( " ", $date );
- $date = explode( $delimiter, $dateTime[0] );
- if ( preg_match( "/(\\d\\d):(\\d\\d):\\d\\d/", $dateTime[1], $matches ) )
- {
- if ( 12 < $matches[1] )
- {
- $matches[1] -= 12;
- $ampm = "pm";
- }
- else if ( $matches[1] == 12 )
- {
- $ampm = "pm";
- }
- else if ( $matches[1] == 0 )
- {
- $matches[1] = 12;
- $ampm = "am";
- }
- else
- {
- $ampm = "am";
- }
- $time = $matches[1].":".$matches[2]." ".$ampm;
- }
- else
- {
- $time = "12:00 am";
- }
- if ( $format && $format == "m/d/Y" )
- {
- return $date[1]."/".$date[2]."/".$date[0]." ".$time;
- }
- return $date[2]."/".$date[1]."/".$date[0]." ".$time;
- }
- if ( $date == "" )
- {
- return "";
- }
- $d = array();
- $d['day'] = mb_substr( $date, 8, 2 );
- $d['month'] = mb_substr( $date, 5, 2 );
- $d['year'] = mb_substr( $date, 0, 4 );
- if ( $format == "m/d/Y" )
- {
- return $d['month'].$delimiter.$d['day'].$delimiter.$d['year'];
- }
- return $d['day'].$delimiter.$d['month'].$delimiter.$d['year'];
- }
- public function form_to_db( $date, $format, $delimiter = ".", $time = FALSE )
- {
- if ( $time )
- {
- if ( preg_match( "#(\\d\\d)".$delimiter."(\\d\\d){$delimiter}(\\d\\d\\d\\d) (\\d{1,2}):(\\d\\d) (am|pm)#", $date, $matches ) )
- {
- if ( $format == "m/d/Y" )
- {
- $month = $matches[1];
- $day = $matches[2];
- }
- else
- {
- list( , $day, $month ) = $matches;
- }
- if ( $matches[6] == "pm" && $matches[4] != 12 )
- {
- $matches[4] += 12;
- }
- return $matches[3].( "-".$month."-{$day} " ).$matches[4].":".$matches[5].":00";
- }
- return "0000-00-00 00:00:00";
- }
- if ( mb_ereg( "([0-9]{1,2})".$delimiter."([0-9]{1,2}){$delimiter}([0-9]{2,4})", $date, $regs ) )
- {
- if ( strlen( $regs[1] ) < 2 )
- {
- $regs[1] = "0".$regs['1'];
- }
- if ( strlen( $regs[2] ) < 2 )
- {
- $regs[2] = "0".$regs['2'];
- }
- if ( strlen( $regs[3] ) < 4 )
- {
- $regs[3] = "20".$regs['3'];
- }
- if ( $format == "m/d/Y" )
- {
- return "{$regs['3']}-{$regs['1']}-{$regs['2']}";
- }
- return "{$regs['3']}-{$regs['2']}-{$regs['1']}";
- }
- return "0000-00-00";
- }
- public function date_diff( $date1, $date2 )
- {
- $s = strtotime( $date2 ) - strtotime( $date1 );
- $d = intval( $s / 86400 );
- $s -= $d * 86400;
- $h = intval( $s / 3600 );
- $s -= $h * 3600;
- $m = intval( $s / 60 );
- $s -= $m * 60;
- return array(
- "d" => $d,
- "h" => $h,
- "m" => $m,
- "s" => $s
- );
- }
- public static function date_diff_hrs( $date1, $date2 )
- {
- $s = strtotime( $date2 ) - strtotime( $date1 );
- $h = intval( $s / 3600 );
- $s -= $h * 3600;
- $m = intval( $s / 60 );
- $s -= $m * 60;
- return array(
- "h" => $h,
- "m" => $m,
- "s" => $s
- );
- }
- public function getMonthLabel( $months, &$user )
- {
- switch ( $months )
- {
- case 0 :
- $tString = "One Time";
- case 1 :
- $tString = $this->user->lang( "Monthly" );
- return $tString;
- case 3 :
- $tString = $this->user->lang( "Quarterly" );
- return $tString;
- case 6 :
- $tString = $this->user->lang( "Semiannually" );
- return $tString;
- case 12 :
- $tString = $this->user->lang( "Annually" );
- return $tString;
- case 12 < $months :
- $tYear = $months / 12;
- $tString = "Every ".$tYear." Years";
- return $tString;
- }
- $tString = "Unkown";
- return $tString;
- }
- public static function writeConfigFile( $installDir, $dbserver, $dbuser, $dbpassword, $dbname, $installed, &$user, &$customer, &$settings )
- {
- include_once( "newedge/classes/NE_Template.php" );
- ( $user, $customer, $settings, "newedge" );
- $tpl = new NE_Template();
- $tpl->no_strict();
- $tpl->define( array( "configFile" => "configFile.tpl" ) );
- $tpl->setKey( array(
- "SERVER" => addslashes( $dbserver ),
- "USER" => addslashes( $dbuser ),
- "PASSWORD" => addslashes( $dbpassword ),
- "DATABASE" => addslashes( $dbname ),
- "INSTALLED" => $installed,
- "LOG_LEVEL" => defined( "LOG_LEVEL" ) ? LOG_LEVEL : 1,
- "LOG_FILE" => defined( "LOG_TEXTFILE" ) && LOG_TEXTFILE ? "'".LOG_TEXTFILE."'" : "false",
- "SESSION_LOGIN" => defined( "SESSION_LOGIN" ) && SESSION_LOGIN ? "true" : "false",
- "DEMO" => defined( "DEMO" ) && DEMO ? "true" : "false",
- "PROFILE" => defined( "PROFILE" ) && PROFILE ? "true" : "false",
- "FIREBUG" => defined( "FIREBUG" ) && FIREBUG ? "true" : "false"
- ) );
- $tpl->parse( "config", "configFile" );
- $fp = @fopen( "{$installDir}/config.php", "w" );
- if ( !$fp )
- {
- return FALSE;
- }
- fputs( $fp, $tpl->fetch( "config" ) );
- fclose( $fp );
- return TRUE;
- }
- public function cleanCache()
- {
- $dir = "uploads/cache/";
- $openDir = @opendir( $dir );
- while ( FALSE !== ( $file = @readdir( $openDir ) ) )
- {
- if ( !( $file != "." ) && !( $file != ".." ) && !( $file != "index.html" ) && !( $file != ".svn" ) )
- {
- @chmod( $dir.$file, 511 );
- @unlink( $dir.$file );
- }
- }
- @closedir( $openDir );
- }
- public static function getSoftwareURL()
- {
- if ( !isset( $_SERVER['HTTP_HOST'] ) )
- {
- $settings = NE_Registry::getsettings();
- if ( !$settings )
- {
- return "";
- }
- $config = NE_Registry::getconfiguration();
- return $settings->get( $config['framework']['appName']." URL" );
- }
- if ( isset( $_SERVER['REQUEST_URI'] ) )
- {
- $uri = $_SERVER['REQUEST_URI'];
- }
- else if ( isset( $_SERVER['PATH_INFO'] ) )
- {
- $uri = $_SERVER['PATH_INFO'];
- }
- else if ( isset( $_SERVER['SCRIPT_NAME'] ) )
- {
- $uri = $_SERVER['SCRIPT_NAME'];
- }
- else
- {
- $uri = "";
- }
- $tmpString = $_SERVER['HTTP_HOST'].$uri;
- $tmpString = str_replace( "\\", "/", $tmpString );
- $pos = strrpos( $tmpString, "/" );
- if ( !( $pos === FALSE ) )
- {
- $tmpString = mb_substr( $tmpString, 0, $pos );
- }
- if ( preg_match( "#(.*)/plugins/gateways/.*#", $tmpString, $matches ) )
- {
- $tmpString = $matches[1];
- }
- if ( NE_ADMIN )
- {
- $tmpString = mb_substr( $tmpString, 0, strlen( $tmpString ) - strlen( NE_CONTROLLER_ADMIN_DIR ) );
- }
- if ( NE_MOBILE )
- {
- $tmpString = mb_substr( $tmpString, 0, strlen( $tmpString ) - strlen( NE_CONTROLLER_MOBILE_DIR ) );
- }
- if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == "on" )
- {
- $protocol = "https";
- }
- else
- {
- $protocol = "http";
- }
- return $protocol."://".$tmpString;
- }
- public static function getSoftwarePath()
- {
- $path = dirname( $_SERVER['SCRIPT_FILENAME'] );
- if ( NE_Lib::ismobiledir() )
- {
- $path = rtrim( $path, "/mobile" );
- return $path;
- }
- if ( !NE_Lib::ispublicdir() )
- {
- $path = rtrim( $path, "/admin" );
- }
- return $path;
- }
- public static function isPublicDir()
- {
- return NE_PUBLIC;
- }
- public function isAdminDir()
- {
- return NE_ADMIN;
- }
- public function isMobileDir()
- {
- return NE_MOBILE;
- }
- public static function compareVersions( $version1, $version2, $versionArray, $stripkeys = TRUE )
- {
- if ( $stripkeys )
- {
- $versions = array_keys( $versionArray );
- }
- else
- {
- $versions = $versionArray;
- }
- return array_search( $version1, $versions ) - array_search( $version2, $versions );
- }
- public static function getPreVersion3ModulesArr()
- {
- return array( "newedge", "home", "clients", "billing", "support", "reports", "files", "admin" );
- }
- public static function getCoreModulesArr( $installation = "clientexec" )
- {
- if ( $installation == "clientexec" )
- {
- return array( "newedge", "home", "clients", "billing", "support", "reports", "files", "admin", "domains", "knowledgebase" );
- }
- }
- public static function removeSlashes( &$data )
- {
- if ( is_array( $data ) )
- {
- foreach ( $data as $k => $v )
- {
- NE_Lib::removeslashes( $data[$k] );
- }
- }
- else
- {
- $data = stripslashes( $data );
- }
- }
- public function generatePassword( $length = 8, $specialChars = FALSE )
- {
- if ( $specialChars )
- {
- $chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ023456789!£\$%^&*?/`~@.";
- }
- else
- {
- $chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ023456789";
- }
- srand( ( double )microtime() * 1000000 );
- $i = 0;
- $pass = "";
- while ( $i <= $length )
- {
- $num = rand() % strlen( $chars ) - 1;
- $tmp = substr( $chars, $num, 1 );
- $pass .= $tmp;
- ++$i;
- }
- return $pass;
- }
- public function parsePhpInfo()
- {
- @ob_start();
- @phpinfo();
- $phpinfo = array(
- "phpinfo" => array()
- );
- if ( preg_match_all( "#(?:<h2>(?:<a name=\".*?\">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?: class=\".*?\")?><t[hd](?: class=\".*?\")?>(.*?)\\s*</t[hd]>(?:<t[hd](?: class=\".*?\")?>(.*?)\\s*</t[hd]>(?:<t[hd](?: class=\".*?\")?>(.*?)\\s*</t[hd]>)?)?</tr>)#s", ob_get_clean(), $matches, PREG_SET_ORDER ) )
- {
- foreach ( $matches as $match )
- {
- if ( strlen( $match[1] ) )
- {
- $phpinfo[$match[1]] = array();
- }
- else if ( array() )
- {
- $phpinfo[end( array_keys( $phpinfo ) )][$match[2]] = isset( $match[3], $match[4] ) ? array(
- $match[3],
- $match[4]
- ) : $match[3];
- }
- else
- {
- $phpinfo[end( array_keys( $phpinfo ) )][] = $match[2];
- }
- }
- }
- return $phpinfo;
- }
- public static function prepareFromDB( $st )
- {
- $st = str_replace( "'", "'", $st );
- $st = str_replace( """, "\"", $st );
- return $st;
- }
- public function prepareForDB( $st )
- {
- $st = str_replace( "'", "'", $st );
- $st = str_replace( "\"", """, $st );
- return $st;
- }
- public function convertCurrencyToHTML( $str )
- {
- $str = str_replace( array(
- chr( 164 ),
- chr( 128 ),
- "����"
- ), array( "€", "€", "€" ), $str );
- $str = str_replace( array(
- chr( 165 ),
- "�¥"
- ), array( "¥", "¥" ), $str );
- return $str;
- }
- public function convertStr( $in_charset, $out_charset, $str )
- {
- if ( $out_charset == $in_charset || $in_charset == "" || $out_charset == "" )
- {
- return $str;
- }
- if ( function_exists( "iconv" ) )
- {
- $result = @iconv( $in_charset, $out_charset, $str );
- if ( $result === FALSE )
- {
- return $str;
- }
- return $result;
- }
- if ( $in_charset == "UTF-8" && $out_charset == "ISO-8859-1" )
- {
- return utf8_decode( $str );
- }
- if ( $in_charset == "ISO-8859-1" && $out_charset == "UTF-8" )
- {
- return utf8_encode( $str );
- }
- return $str;
- }
- public function replaceCustomFields( &$db, $strEmailString, $userid, $dateFormat, $domainid = 0 )
- {
- require_once( "modules/clients/models/ObjectCustomFields.php" );
- $query = "SELECT c.name,c.type,cv.value FROM customuserfields c, user_customuserfields cv where cv.customid=c.id and cv.userid=?";
- $result = $db->query( $query, $userid );
- while ( list( $tName, $tType, $tValue ) = $result->fetch() )
- {
- $tName = "[CUSTOMPROFILE_".$tName."]";
- $tValue = NE_Lib::_parsecustomfieldtype( $tType, $tValue, $dateFormat );
- $strEmailString = str_replace( $tName, $tValue, $strEmailString );
- }
- if ( $domainid != 0 )
- {
- $query = "SELECT c.name, c.fieldType, cv.value FROM customField c, object_customField cv WHERE cv.customFieldId = c.id AND cv.objectid = ? AND c.groupId = ".CUSTOM_FIELDS_FOR_PACKAGE." ";
- $result = $db->query( $query, $domainid );
- while ( list( $tName, $tType, $tValue ) = $result->fetch() )
- {
- $tName = "[CUSTOMPACKAGE_".$tName."]";
- $tValue = NE_Lib::_parsecustomfieldtype( $tType, $tValue, $dateFormat );
- $strEmailString = str_replace( $tName, $tValue, $strEmailString );
- }
- }
- $strEmailString = preg_replace( "/\\[CUSTOM.*\\]/U", "", $strEmailString );
- return $strEmailString;
- }
- public function _parseCustomFieldType( $type, $value, $dateFormat )
- {
- $newValue = "";
- switch ( $type )
- {
- case typeYESNO :
- if ( $value == 0 )
- {
- $newValue = "No";
- return $newValue;
- }
- $newValue = "Yes";
- return $newValue;
- case TYPEDATE :
- if ( $value != "" )
- {
- break;
- }
- $newValue = NE_Lib::db_to_form( $value, $dateFormat, "/" );
- }
- $newValue = $value;
- return $newValue;
- }
- public function getCustomUserFieldIDForName( &$db, $name )
- {
- $query = "select id from customuserfields where name=?";
- $result = $db->query( $query, $name );
- list( $tID ) = $result->fetch();
- return $tID;
- }
- public function download( $str, $filename )
- {
- header( "Content-type: application/octet-stream" );
- header( "Content-Disposition: attachment; filename=\"".$filename."\"" );
- header( "Content-Length: ".strlen( $str ) );
- header( "Pragma: public" );
- header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
- header( "Expires: 0" );
- echo $str;
- exit();
- }
- public function getBasicConfiguration( $frameworkConfig, $hostname, $dbuser, $dbpass, $database, $dbEncoding, $sessionName )
- {
- $configuration = array(
- "framework" => array(
- "appName" => $frameworkConfig['appName'],
- "appVersion" => $frameworkConfig['appVersion'],
- "appVersions" => $frameworkConfig['appVersions'],
- "errorLevel" => $frameworkConfig['errorLevel'],
- "displayErrors" => $frameworkConfig['displayErrors'],
- "dbEngine" => $frameworkConfig['dbEngine'],
- "dbDefaultEncoding" => $frameworkConfig['dbDefaultEncoding'],
- "defaultLanguage" => $frameworkConfig['defaultLanguage'],
- "defaultCharSet" => $frameworkConfig['defaultCharSet'],
- "defaultTemplate" => $frameworkConfig['defaultTemplate'],
- "defaultModule" => $frameworkConfig['defaultModule'],
- "defaultModule_Mobile" => $frameworkConfig['defaultModule_Mobile'],
- "hooksPublicSection" => $frameworkConfig['hooksPublicSection'],
- "specialConfigurations" => $frameworkConfig['specialConfigurations'],
- "pluginTypes" => $frameworkConfig['pluginTypes'],
- "maskInLog" => $frameworkConfig['maskInLog']
- ),
- "application" => array(
- "dbHostname" => $hostname,
- "dbUser" => $dbuser,
- "dbPassword" => $dbpass,
- "dbSchema" => $database,
- "dbEncoding" => $dbEncoding,
- "sessionName" => $sessionName,
- "installed" => INSTALLED,
- "logLevel" => defined( "LOG_LEVEL" ) ? LOG_LEVEL : NULL,
- "logScreen" => defined( "LOG_SCREEN" ) ? LOG_SCREEN : NULL,
- "logTextFile" => defined( "LOG_TEXTFILE" ) ? LOG_TEXTFILE : NULL
- ),
- "modules" => array()
- );
- return $configuration;
- }
- public static function getModulesConfiguration( $currentConfiguration, $getInstalledVersion = FALSE )
- {
- $configuration = array();
- $db =& NE_Registry::getdatabase();
- if ( isset( $_SESSION['moduleconfigs'] ) )
- {
- $configuration = unserialize( $_SESSION['moduleconfigs'] );
- return $configuration;
- }
- if ( !is_a( $db, "NE_Error" ) || $getInstalledVersion )
- {
- $installedModules = array();
- $query = "SELECT module, version FROM versions";
- $db->setSkipFatalError( TRUE );
- $result = $db->query( $query );
- $db->setSkipFatalError( FALSE );
- while ( !is_a( $result, "NE_Error" ) || ( $row = $result->fetch() ) )
- {
- $installedModules[$row['module']] = $row['version'];
- }
- }
- include( "newedge/config.php" );
- $configuration['newedge'] = $config;
- if ( isset( $installedModules['newedge'] ) )
- {
- $configuration['newedge']['installedVersion'] = $installedModules['newedge'];
- }
- $modulesPath = realpath( dirname( __FILE__ )."/../../modules" );
- $dir = dir( $modulesPath );
- for ( ; while ( FALSE !== ( $entry = $dir->read() ) )
- {
- if ( isset( $currentConfiguration['framework']['specialConfigurations'][$entry] ) )
- {
- $configFileName = $currentConfiguration['framework']['specialConfigurations'][$entry], }
- else
- {
- $configFileName = "config.php", }
- if ( in_array( $entry, array( ".", "..", "CVS", ".svn" ) ) )
- {
- break;
- }
- is_dir( "{$modulesPath}/{$entry}" ) && is_readable( "{$modulesPath}/{$entry}/{$configFileName}" ); }
- )
- {
- include( "{$modulesPath}/{$entry}/{$configFileName}" );
- $configuration[$entry] = $config;
- if ( isset( $installedModules[$entry] ) )
- {
- $configuration[$entry]['installedVersion'] = $installedModules[$entry];
- }
- }
- uasort( &$configuration, array( "NE_Lib", "_sortConfig" ) );
- $_SESSION['moduleconfigs'] = serialize( $configuration );
- return $configuration;
- }
- public function getOldFrameworkAppVersion()
- {
- $db =& NE_Registry::getdatabase();
- $configuration = NE_Registry::getconfiguration();
- if ( !is_a( $db, "NE_Error" ) )
- {
- $query = "SELECT value FROM `setting` WHERE name=?";
- $result = @$this->db->query( $query, $configuration['framework']['appName']." Version" );
- list( $version ) = $result->fetch();
- if ( $version )
- {
- return $version;
- }
- }
- return FALSE;
- }
- public function _sortConfig( $a, $b )
- {
- if ( $a == "newedge" || $a['order'] < $b['order'] )
- {
- return -1;
- }
- if ( $b == "newedge" || $b['order'] < $a['order'] )
- {
- return 1;
- }
- return 0;
- }
- public function _array_map_recursive( $func, $arr )
- {
- $newArr = array();
- foreach ( $arr as $key => $value )
- {
- if ( is_array( $value ) )
- {
- $newArr[$key] = NE_Lib::_array_map_recursive( $func, $value );
- }
- else if ( is_array( $func ) && is_string( $func[0] ) )
- {
- $newArr[$key] = call_user_func( array(
- $func[0],
- $func[1]
- ), $value );
- }
- else if ( is_array( $func ) && is_object( $func[0] ) )
- {
- $newArr[$key] = $func[0]->$func[1]( $value );
- }
- else
- {
- $newArr[$key] = $func( $value );
- }
- }
- return $newArr;
- }
- public function encryptData( $text, $key )
- {
- if ( !extension_loaded( "mcrypt" ) )
- {
- ( "Error: you don't have the mcrypt extension enabled" );
- return new NE_Error();
- }
- $iv_size = mcrypt_get_iv_size( MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB );
- $iv = mcrypt_create_iv( $iv_size, MCRYPT_RAND );
- $crypttext = mcrypt_encrypt( MCRYPT_TRIPLEDES, $key, $text, MCRYPT_MODE_ECB, $iv );
- return $crypttext;
- }
- public function decryptData( $text, $key )
- {
- if ( !extension_loaded( "mcrypt" ) )
- {
- ( "Error: you don't have the mcrypt extension enabled" );
- return new NE_Error();
- }
- $iv_size = mcrypt_get_iv_size( MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB );
- $iv = mcrypt_create_iv( $iv_size, MCRYPT_RAND );
- $decrypttext = mcrypt_decrypt( MCRYPT_TRIPLEDES, $key, $text, MCRYPT_MODE_ECB, $iv );
- return rtrim( $decrypttext );
- }
- public function getExecutable( $locations )
- {
- if ( strtoupper( mb_substr( PHP_OS, 0, 3 ) ) == "WIN" )
- {
- return FALSE;
- }
- foreach ( $locations as $location )
- {
- if ( !@is_executable( $location ) )
- {
- continue;
- }
- return $location;
- }
- return FALSE;
- }
- public static function redirectPage( $redirectURL, $message = "", $extraVarsArr = FALSE )
- {
- $redirectURL = str_replace( "&", "&", $redirectURL );
- $extraVars = array();
- if ( $extraVarsArr )
- {
- foreach ( $extraVarsArr as $varName => $varValue )
- {
- $extraVars[] = "{$varName}={$varValue}";
- }
- }
- if ( $extraVars )
- {
- if ( strpos( $redirectURL, "?" ) !== FALSE )
- {
- $extraVarsStr = "&";
- }
- else
- {
- $extraVarsStr = "?";
- }
- $extraVarsStr .= implode( "&", $extraVars );
- }
- else
- {
- $extraVarsStr = "";
- }
- if ( $message )
- {
- NE_Lib::addmessage( $message );
- }
- header( "Location: ".$redirectURL.$extraVarsStr );
- exit();
- }
- public function addMessage( $message )
- {
- if ( !isset( $_SESSION['messages'] ) )
- {
- return;
- }
- if ( is_array( $message ) )
- {
- $_SESSION['messages'] = array_merge( $_SESSION['messages'], $message );
- }
- else
- {
- $_SESSION['messages'][] = $message;
- }
- }
- public function showErrorMsg( $errorEnum, &$user, $templateName, $returnHTML = FALSE )
- {
- $text = "<table><tr><td valign=middle><font color=red>";
- switch ( $errorEnum )
- {
- case errDuplicateEmail :
- $text .= "That E-mail is already in use, please make the appropriate changes and re-submit.";
- break;
- case errDuplicateDomainName :
- $text .= "That Domain is already in use, please make the appropriate changes and re-submit.";
- break;
- case errDuplicateUserName :
- $text .= "That Username is already in use, please make the appropriate changes and re-submit.";
- break;
- case ERRINCORRECTPASSPHRASE :
- $text .= "You have used a passphrase that has not been used in the past.<br>If you want to change your passphrase please go the admin tool to validate all your credit cards with the new passphrase";
- break;
- case errCCExpiresInPast :
- $text .= $user->lang( "The credit card has already expired" );
- break;
- case errUsersLimitReached :
- $text .= $user->lang( "You have reached your number of users limit" );
- }
- $text .= "</font></td></tr></table>";
- if ( $returnHTML )
- {
- return $text;
- }
- echo $text;
- }
- public function isPassphraseLimbo( &$db )
- {
- $query = "select id from users where updating=1 and passphrased=1";
- $result = $db->query( $query );
- $num = $result->fetch();
- if ( 0 < $num )
- {
- return TRUE;
- }
- return FALSE;
- }
- public function decodehtmlspecialchars( $text )
- {
- if ( function_exists( "htmlspecialchars_decode" ) )
- {
- return htmlspecialchars_decode( $text );
- }
- return strtr( $text, array_flip( get_html_translation_table( HTML_SPECIALCHARS ) ) );
- }
- public function processXML( $dataArray, $level = 1, $startTag = "array" )
- {
- $xml = "";
- if ( $level == 1 )
- {
- $xml .= "<".$startTag.">\n";
- }
- foreach ( $dataArray as $key => $value )
- {
- $key = strtolower( $key );
- if ( is_object( $value ) )
- {
- $value = get_object_vars( $value );
- }
- if ( is_array( $value ) )
- {
- $multi_tags = FALSE;
- foreach ( $value as $key2 => $value2 )
- {
- if ( is_object( $value2 ) )
- {
- $value2 = get_object_vars( $value2 );
- }
- if ( is_array( $value2 ) )
- {
- $xml .= str_repeat( "\t", $level ).( "<".$key.">\n" );
- $xml .= NE_Lib::processxml( $value2, $level + 1 );
- $xml .= str_repeat( "\t", $level ).( "</".$key.">\n" );
- $multi_tags = TRUE;
- }
- else
- {
- if ( trim( $value2 ) != "" )
- {
- if ( htmlspecialchars( $value2 ) != $value2 )
- {
- $xml .= str_repeat( "\t", $level ).( "<".$key2."><![CDATA[{$value2}]]>" ).( "</".$key2.">\n" );
- }
- else
- {
- $xml .= str_repeat( "\t", $level ).( "<".$key2.">{$value2}</{$key2}>\n" );
- }
- }
- $multi_tags = TRUE;
- }
- }
- if ( !$multi_tags )
- {
- if ( 0 < count( $value ) )
- {
- $xml .= str_repeat( "\t", $level ).( "<".$key.">\n" );
- $xml .= NE_Lib::processxml( $value, $level + 1 );
- $xml .= str_repeat( "\t", $level ).( "</".$key.">\n" );
- }
- }
- }
- else if ( trim( $value ) != "" )
- {
- if ( htmlspecialchars( $value ) != $value )
- {
- $xml .= str_repeat( "\t", $level ).( "<".$key.">" ).( "<![CDATA[".$value."]]></{$key}>\n" );
- }
- else
- {
- $xml .= str_repeat( "\t", $level ).( "<".$key.">{$value}</{$key}>\n" );
- }
- }
- }
- if ( $level == 1 )
- {
- $xml .= "</".$startTag.">\n";
- }
- return $xml;
- }
- }
- if ( !function_exists( "json_encode" ) )
- {
- require_once( "newedge/classes/Services/JSON.php" );
- function json_encode( $a )
- {
- ();
- $json = new Services_JSON();
- return $json->encode( $a );
- }
- }
- if ( !function_exists( "json_decode" ) )
- {
- require_once( "newedge/classes/Services/JSON.php" );
- function json_decode( $a )
- {
- ();
- $json = new Services_JSON();
- return $json->decode( $a );
- }
- }
- if ( !function_exists( "mb_substr_replace" ) )
- {
- function mb_substr_replace( $string, $replacement, $start, $length = NULL, $encoding = "UTF-8" )
- {
- if ( $encoding == NULL )
- {
- if ( $length == NULL )
- {
- return mb_substr( $string, 0, $start ).$replacement;
- }
- return mb_substr( $string, 0, $start ).$replacement.mb_substr( $string, $start + $length );
- }
- if ( $length == NULL )
- {
- return mb_substr( $string, 0, $start, $encoding ).$replacement;
- }
- return mb_substr( $string, 0, $start, $encoding ).$replacement.mb_substr( $string, $start + $length, mb_strlen( $string, $encoding ), $encoding );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement