Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 36.55 KB | None | 0 0
  1. <?php
  2.  
  3. class NE_Lib
  4. {
  5.  
  6.     public function NE_Lib()
  7.     {
  8.         exit( "Don't instantiate the NE_Lib class!" );
  9.     }
  10.  
  11.     public function printR( $var, $terminate = FALSE )
  12.     {
  13.         echo "\n<pre>".print_r( $var, TRUE )."</pre>\n";
  14.         if ( $terminate )
  15.         {
  16.             exit();
  17.         }
  18.     }
  19.  
  20.     public function getStack( $hidePaths )
  21.     {
  22.         $stack = debug_backtrace();
  23.         array_shift( &$stack );
  24.         $stackPretty = array();
  25.         foreach ( $stack as $call )
  26.         {
  27.             if ( isset( $call['file'] ) )
  28.             {
  29.                 if ( $hidePaths )
  30.                 {
  31.                     $call['file'] = mb_substr( $call['file'], strrpos( $call['file'], "\\" ) + 1 );
  32.                 }
  33.             }
  34.             else
  35.             {
  36.                 $call['file'] = "no file";
  37.             }
  38.             $stackPretty[] = $call['file']." (".( isset( $call['line'] ) ? $call['line'] : "no line" ).") : ".( isset( $call['class'] ) ? $call['class']."::" : "" ).$call['function'];
  39.         }
  40.         return $stackPretty;
  41.     }
  42.  
  43.     public function getStackCaller()
  44.     {
  45.         $info = array( "file" => "no file", "line" => "no line" );
  46.         $level = 3;
  47.         $stack = debug_backtrace();
  48.         if ( isset( $stack[$level]['file'] ) )
  49.         {
  50.             $info['file'] = mb_substr( $stack[$level]['file'], strrpos( $stack[$level]['file'], "\\" ) + 1 );
  51.         }
  52.         if ( isset( $stack[$level]['line'] ) )
  53.         {
  54.             $info['line'] = $stack[$level]['line'];
  55.         }
  56.         return $info;
  57.     }
  58.  
  59.     public function returnPopUpString( $strPopUpText, &$settings, $strURL = "", $tLink = "NONE", $extra = "", $isPublicView = FALSE )
  60.     {
  61.         if ( $strURL == "" )
  62.         {
  63.             $strURL = "javascript:void(0);";
  64.         }
  65.         $strPopUpText = preg_replace( "/\r\n|\n\r|\n|\r/", " ", $strPopUpText );
  66.         $strPopUpText = str_replace( "'", "&#39;", $strPopUpText );
  67.         $strPopUpText = str_replace( "\"", """, $strPopUpText );
  68.        $strPopUpText = htmlspecialchars( $strPopUpText, ENT_QUOTES );
  69.        if ( $tLink == "NONE" )
  70.        {
  71.            $dir = NE_Lib::ispublicdir() ? "" : "../";
  72.            $tLink = "<img src=\"".$dir.( "images/information-button.png\" alt='' qtip=\"".$strPopUpText."\" border=\"0\" style=\"position:relative; left:0px; top:2px\" />" );
  73.         }
  74.         $strReturnString = "<a href=\"".$strURL."\" qtip=\"{$strPopUpText}\" {$extra}>{$tLink}</a>";
  75.         return $strReturnString;
  76.     }
  77.  
  78.     public function getHighlight( $words, $haystack, $hs = "<font class=searchfound>", $he = "</font>" )
  79.     {
  80.         if ( is_array( $words ) )
  81.         {
  82.             foreach ( $words as $word )
  83.             {
  84.                 $haystack = preg_replace( "|\\b(".quotemeta( $word ).")\\b|iU", $hs."\\1".$he, $haystack );
  85.             }
  86.             return $haystack;
  87.         }
  88.         $haystack = preg_replace( "|\\b(".quotemeta( $words ).")\\b|iU", $hs."\\1".$he, $haystack );
  89.         return $haystack;
  90.     }
  91.  
  92.     public function escapeHTMLAttributeValue( $st )
  93.     {
  94.         $st = str_replace( "\"", """, $st );
  95.        return $st;
  96.    }
  97.  
  98.    public function is_utf8( $str )
  99.    {
  100.        $c = 0;
  101.        $b = 0;
  102.        $bits = 0;
  103.        $len = strlen( $str );
  104.        $i = 0;
  105.        for ( ; $i < $len; ++$i )
  106.        {
  107.            $c = ord( $str[$i] );
  108.            if ( !( 128 < $c ) )
  109.            {
  110.                continue;
  111.            }
  112.            if ( 254 <= $c )
  113.            {
  114.                return FALSE;
  115.            }
  116.            if ( 252 <= $c )
  117.            {
  118.                $bits = 6;
  119.            }
  120.            else if ( 248 <= $c )
  121.            {
  122.                $bits = 5;
  123.            }
  124.            else if ( 240 <= $c )
  125.            {
  126.                $bits = 4;
  127.            }
  128.            else if ( 224 <= $c )
  129.            {
  130.                $bits = 3;
  131.            }
  132.            else if ( 192 <= $c )
  133.            {
  134.                $bits = 2;
  135.            }
  136.            else
  137.            {
  138.                return FALSE;
  139.            }
  140.            if ( $len < $i + $bits )
  141.            {
  142.                return FALSE;
  143.            }
  144.            while ( 1 < $bits )
  145.            {
  146.                ++$i;
  147.                $b = ord( $str[$i] );
  148.                if ( $b < 128 || 191 < $b )
  149.                {
  150.                    return FALSE;
  151.                }
  152.                --$bits;
  153.            }
  154.        }
  155.        return TRUE;
  156.    }
  157.  
  158.    public function convToUtf8( $str )
  159.    {
  160.        if ( mb_detect_encoding( $str, "UTF-8, ISO-8859-1, GBK" ) != "UTF-8" )
  161.        {
  162.            return iconv( "gbk", "utf-8", $str );
  163.        }
  164.        return $str;
  165.    }
  166.  
  167.    public function jsonencode( $a = FALSE )
  168.    {
  169.        try
  170.        {
  171.            if ( version_compare( phpversion(), "5.2.0", "<" ) )
  172.            {
  173.                require_once( "newedge/classes/Services/JSON.php" );
  174.                ();
  175.                $json = new Services_JSON();
  176.                $ret = $json->encode( $a );
  177.                return $ret;
  178.            }
  179.            $ret = json_encode( $a );
  180.            return $ret;
  181.        }
  182.        catch ( Exception $ex )
  183.        {
  184.            $this->logger->log( 1, $ex->getMessage() );
  185.            $this->logger->log( 1, $a );
  186.        }
  187.    }
  188.  
  189.    public function escapeJSON( $value )
  190.    {
  191.        $search = array( "\\", "\r\n", "\r", "\n", "\"", "/", "\\b", "\\f", "\t" );
  192.         $replace = array( "\\\\", "\\r\\n", "\\r", "\\n", "\\\"", "\\/", "\\b", "\\f", "\\t" );
  193.         return str_replace( $search, $replace, $value );
  194.     }
  195.  
  196.     public function getAltColor( &$intColorIndex )
  197.     {
  198.         if ( $intColorIndex == 0 )
  199.         {
  200.             $strColor = "primarycolor";
  201.             $intColorIndex = 1;
  202.             return $strColor;
  203.         }
  204.         $strColor = "secondarycolor";
  205.         $intColorIndex = 0;
  206.         return $strColor;
  207.     }
  208.  
  209.     public static function db_to_form( $date, $format, $delimiter = ".", $time = FALSE )
  210.     {
  211.         if ( $time )
  212.         {
  213.             $dateTime = explode( " ", $date );
  214.             $date = explode( $delimiter, $dateTime[0] );
  215.             if ( preg_match( "/(\\d\\d):(\\d\\d):\\d\\d/", $dateTime[1], $matches ) )
  216.             {
  217.                 if ( 12 < $matches[1] )
  218.                 {
  219.                     $matches[1] -= 12;
  220.                     $ampm = "pm";
  221.                 }
  222.                 else if ( $matches[1] == 12 )
  223.                 {
  224.                     $ampm = "pm";
  225.                 }
  226.                 else if ( $matches[1] == 0 )
  227.                 {
  228.                     $matches[1] = 12;
  229.                     $ampm = "am";
  230.                 }
  231.                 else
  232.                 {
  233.                     $ampm = "am";
  234.                 }
  235.                 $time = $matches[1].":".$matches[2]." ".$ampm;
  236.             }
  237.             else
  238.             {
  239.                 $time = "12:00 am";
  240.             }
  241.             if ( $format && $format == "m/d/Y" )
  242.             {
  243.                 return $date[1]."/".$date[2]."/".$date[0]."  ".$time;
  244.             }
  245.             return $date[2]."/".$date[1]."/".$date[0]."  ".$time;
  246.         }
  247.         if ( $date == "" )
  248.         {
  249.             return "";
  250.         }
  251.         $d = array();
  252.         $d['day'] = mb_substr( $date, 8, 2 );
  253.         $d['month'] = mb_substr( $date, 5, 2 );
  254.         $d['year'] = mb_substr( $date, 0, 4 );
  255.         if ( $format == "m/d/Y" )
  256.         {
  257.             return $d['month'].$delimiter.$d['day'].$delimiter.$d['year'];
  258.         }
  259.         return $d['day'].$delimiter.$d['month'].$delimiter.$d['year'];
  260.     }
  261.  
  262.     public function form_to_db( $date, $format, $delimiter = ".", $time = FALSE )
  263.     {
  264.         if ( $time )
  265.         {
  266.             if ( preg_match( "#(\\d\\d)".$delimiter."(\\d\\d){$delimiter}(\\d\\d\\d\\d) (\\d{1,2}):(\\d\\d) (am|pm)#", $date, $matches ) )
  267.             {
  268.                 if ( $format == "m/d/Y" )
  269.                 {
  270.                     $month = $matches[1];
  271.                     $day = $matches[2];
  272.                 }
  273.                 else
  274.                 {
  275.                     list( , $day, $month ) = $matches;
  276.                 }
  277.                 if ( $matches[6] == "pm" && $matches[4] != 12 )
  278.                 {
  279.                     $matches[4] += 12;
  280.                 }
  281.                 return $matches[3].( "-".$month."-{$day} " ).$matches[4].":".$matches[5].":00";
  282.             }
  283.             return "0000-00-00 00:00:00";
  284.         }
  285.         if ( mb_ereg( "([0-9]{1,2})".$delimiter."([0-9]{1,2}){$delimiter}([0-9]{2,4})", $date, $regs ) )
  286.         {
  287.             if ( strlen( $regs[1] ) < 2 )
  288.             {
  289.                 $regs[1] = "0".$regs['1'];
  290.             }
  291.             if ( strlen( $regs[2] ) < 2 )
  292.             {
  293.                 $regs[2] = "0".$regs['2'];
  294.             }
  295.             if ( strlen( $regs[3] ) < 4 )
  296.             {
  297.                 $regs[3] = "20".$regs['3'];
  298.             }
  299.             if ( $format == "m/d/Y" )
  300.             {
  301.                 return "{$regs['3']}-{$regs['1']}-{$regs['2']}";
  302.             }
  303.             return "{$regs['3']}-{$regs['2']}-{$regs['1']}";
  304.         }
  305.         return "0000-00-00";
  306.     }
  307.  
  308.     public function date_diff( $date1, $date2 )
  309.     {
  310.         $s = strtotime( $date2 ) - strtotime( $date1 );
  311.         $d = intval( $s / 86400 );
  312.         $s -= $d * 86400;
  313.         $h = intval( $s / 3600 );
  314.         $s -= $h * 3600;
  315.         $m = intval( $s / 60 );
  316.         $s -= $m * 60;
  317.         return array(
  318.             "d" => $d,
  319.             "h" => $h,
  320.             "m" => $m,
  321.             "s" => $s
  322.         );
  323.     }
  324.  
  325.     public static function date_diff_hrs( $date1, $date2 )
  326.     {
  327.         $s = strtotime( $date2 ) - strtotime( $date1 );
  328.         $h = intval( $s / 3600 );
  329.         $s -= $h * 3600;
  330.         $m = intval( $s / 60 );
  331.         $s -= $m * 60;
  332.         return array(
  333.             "h" => $h,
  334.             "m" => $m,
  335.             "s" => $s
  336.         );
  337.     }
  338.  
  339.     public function getMonthLabel( $months, &$user )
  340.     {
  341.         switch ( $months )
  342.         {
  343.         case 0 :
  344.             $tString = "One Time";
  345.         case 1 :
  346.             $tString = $this->user->lang( "Monthly" );
  347.             return $tString;
  348.         case 3 :
  349.             $tString = $this->user->lang( "Quarterly" );
  350.             return $tString;
  351.         case 6 :
  352.             $tString = $this->user->lang( "Semiannually" );
  353.             return $tString;
  354.         case 12 :
  355.             $tString = $this->user->lang( "Annually" );
  356.             return $tString;
  357.         case 12 < $months :
  358.             $tYear = $months / 12;
  359.             $tString = "Every ".$tYear." Years";
  360.             return $tString;
  361.         }
  362.         $tString = "Unkown";
  363.         return $tString;
  364.     }
  365.  
  366.     public static function writeConfigFile( $installDir, $dbserver, $dbuser, $dbpassword, $dbname, $installed, &$user, &$customer, &$settings )
  367.     {
  368.         include_once( "newedge/classes/NE_Template.php" );
  369.         ( $user, $customer, $settings, "newedge" );
  370.         $tpl = new NE_Template();
  371.         $tpl->no_strict();
  372.         $tpl->define( array( "configFile" => "configFile.tpl" ) );
  373.         $tpl->setKey( array(
  374.             "SERVER" => addslashes( $dbserver ),
  375.             "USER" => addslashes( $dbuser ),
  376.             "PASSWORD" => addslashes( $dbpassword ),
  377.             "DATABASE" => addslashes( $dbname ),
  378.             "INSTALLED" => $installed,
  379.             "LOG_LEVEL" => defined( "LOG_LEVEL" ) ? LOG_LEVEL : 1,
  380.             "LOG_FILE" => defined( "LOG_TEXTFILE" ) && LOG_TEXTFILE ? "'".LOG_TEXTFILE."'" : "false",
  381.             "SESSION_LOGIN" => defined( "SESSION_LOGIN" ) && SESSION_LOGIN ? "true" : "false",
  382.             "DEMO" => defined( "DEMO" ) && DEMO ? "true" : "false",
  383.             "PROFILE" => defined( "PROFILE" ) && PROFILE ? "true" : "false",
  384.             "FIREBUG" => defined( "FIREBUG" ) && FIREBUG ? "true" : "false"
  385.         ) );
  386.         $tpl->parse( "config", "configFile" );
  387.         $fp = @fopen( "{$installDir}/config.php", "w" );
  388.         if ( !$fp )
  389.         {
  390.             return FALSE;
  391.         }
  392.         fputs( $fp, $tpl->fetch( "config" ) );
  393.         fclose( $fp );
  394.         return TRUE;
  395.     }
  396.  
  397.     public function cleanCache()
  398.     {
  399.         $dir = "uploads/cache/";
  400.         $openDir = @opendir( $dir );
  401.         while ( FALSE !== ( $file = @readdir( $openDir ) ) )
  402.         {
  403.             if ( !( $file != "." ) && !( $file != ".." ) && !( $file != "index.html" ) && !( $file != ".svn" ) )
  404.             {
  405.                 @chmod( $dir.$file, 511 );
  406.                 @unlink( $dir.$file );
  407.             }
  408.         }
  409.         @closedir( $openDir );
  410.     }
  411.  
  412.     public static function getSoftwareURL()
  413.     {
  414.         if ( !isset( $_SERVER['HTTP_HOST'] ) )
  415.         {
  416.             $settings = NE_Registry::getsettings();
  417.             if ( !$settings )
  418.             {
  419.                 return "";
  420.             }
  421.             $config = NE_Registry::getconfiguration();
  422.             return $settings->get( $config['framework']['appName']." URL" );
  423.         }
  424.         if ( isset( $_SERVER['REQUEST_URI'] ) )
  425.         {
  426.             $uri = $_SERVER['REQUEST_URI'];
  427.         }
  428.         else if ( isset( $_SERVER['PATH_INFO'] ) )
  429.         {
  430.             $uri = $_SERVER['PATH_INFO'];
  431.         }
  432.         else if ( isset( $_SERVER['SCRIPT_NAME'] ) )
  433.         {
  434.             $uri = $_SERVER['SCRIPT_NAME'];
  435.         }
  436.         else
  437.         {
  438.             $uri = "";
  439.         }
  440.         $tmpString = $_SERVER['HTTP_HOST'].$uri;
  441.         $tmpString = str_replace( "\\", "/", $tmpString );
  442.         $pos = strrpos( $tmpString, "/" );
  443.         if ( !( $pos === FALSE ) )
  444.         {
  445.             $tmpString = mb_substr( $tmpString, 0, $pos );
  446.         }
  447.         if ( preg_match( "#(.*)/plugins/gateways/.*#", $tmpString, $matches ) )
  448.         {
  449.             $tmpString = $matches[1];
  450.         }
  451.         if ( NE_ADMIN )
  452.         {
  453.             $tmpString = mb_substr( $tmpString, 0, strlen( $tmpString ) - strlen( NE_CONTROLLER_ADMIN_DIR ) );
  454.         }
  455.         if ( NE_MOBILE )
  456.         {
  457.             $tmpString = mb_substr( $tmpString, 0, strlen( $tmpString ) - strlen( NE_CONTROLLER_MOBILE_DIR ) );
  458.         }
  459.         if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == "on" )
  460.         {
  461.             $protocol = "https";
  462.         }
  463.         else
  464.         {
  465.             $protocol = "http";
  466.         }
  467.         return $protocol."://".$tmpString;
  468.     }
  469.  
  470.     public static function getSoftwarePath()
  471.     {
  472.         $path = dirname( $_SERVER['SCRIPT_FILENAME'] );
  473.         if ( NE_Lib::ismobiledir() )
  474.         {
  475.             $path = rtrim( $path, "/mobile" );
  476.             return $path;
  477.         }
  478.         if ( !NE_Lib::ispublicdir() )
  479.         {
  480.             $path = rtrim( $path, "/admin" );
  481.         }
  482.         return $path;
  483.     }
  484.  
  485.     public static function isPublicDir()
  486.     {
  487.         return NE_PUBLIC;
  488.     }
  489.  
  490.     public function isAdminDir()
  491.     {
  492.         return NE_ADMIN;
  493.     }
  494.  
  495.     public function isMobileDir()
  496.     {
  497.         return NE_MOBILE;
  498.     }
  499.  
  500.     public static function compareVersions( $version1, $version2, $versionArray, $stripkeys = TRUE )
  501.     {
  502.         if ( $stripkeys )
  503.         {
  504.             $versions = array_keys( $versionArray );
  505.         }
  506.         else
  507.         {
  508.             $versions = $versionArray;
  509.         }
  510.         return array_search( $version1, $versions ) - array_search( $version2, $versions );
  511.     }
  512.  
  513.     public static function getPreVersion3ModulesArr()
  514.     {
  515.         return array( "newedge", "home", "clients", "billing", "support", "reports", "files", "admin" );
  516.     }
  517.  
  518.     public static function getCoreModulesArr( $installation = "clientexec" )
  519.     {
  520.         if ( $installation == "clientexec" )
  521.         {
  522.             return array( "newedge", "home", "clients", "billing", "support", "reports", "files", "admin", "domains", "knowledgebase" );
  523.         }
  524.     }
  525.  
  526.     public static function removeSlashes( &$data )
  527.     {
  528.         if ( is_array( $data ) )
  529.         {
  530.             foreach ( $data as $k => $v )
  531.             {
  532.                 NE_Lib::removeslashes( $data[$k] );
  533.             }
  534.         }
  535.         else
  536.         {
  537.             $data = stripslashes( $data );
  538.         }
  539.     }
  540.  
  541.     public function generatePassword( $length = 8, $specialChars = FALSE )
  542.     {
  543.         if ( $specialChars )
  544.         {
  545.             $chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ023456789!£\$%^&*?/`~@.";
  546.         }
  547.         else
  548.         {
  549.             $chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ023456789";
  550.         }
  551.         srand( ( double )microtime() * 1000000 );
  552.         $i = 0;
  553.         $pass = "";
  554.         while ( $i <= $length )
  555.         {
  556.             $num = rand() % strlen( $chars ) - 1;
  557.             $tmp = substr( $chars, $num, 1 );
  558.             $pass .= $tmp;
  559.             ++$i;
  560.         }
  561.         return $pass;
  562.     }
  563.  
  564.     public function parsePhpInfo()
  565.     {
  566.         @ob_start();
  567.         @phpinfo();
  568.         $phpinfo = array(
  569.             "phpinfo" => array()
  570.         );
  571.         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 ) )
  572.         {
  573.             foreach ( $matches as $match )
  574.             {
  575.                 if ( strlen( $match[1] ) )
  576.                 {
  577.                     $phpinfo[$match[1]] = array();
  578.                 }
  579.                 else if ( array() )
  580.                 {
  581.                     $phpinfo[end( array_keys( $phpinfo ) )][$match[2]] = isset( $match[3], $match[4] ) ? array(
  582.                         $match[3],
  583.                         $match[4]
  584.                     ) : $match[3];
  585.                 }
  586.                 else
  587.                 {
  588.                     $phpinfo[end( array_keys( $phpinfo ) )][] = $match[2];
  589.                 }
  590.             }
  591.         }
  592.         return $phpinfo;
  593.     }
  594.  
  595.     public static function prepareFromDB( $st )
  596.     {
  597.         $st = str_replace( "&#039;", "'", $st );
  598.         $st = str_replace( """, "\"", $st );
  599.         return $st;
  600.     }
  601.  
  602.     public function prepareForDB( $st )
  603.     {
  604.         $st = str_replace( "'", "&#039;", $st );
  605.         $st = str_replace( "\"", """, $st );
  606.        return $st;
  607.    }
  608.  
  609.    public function convertCurrencyToHTML( $str )
  610.    {
  611.        $str = str_replace( array(
  612.            chr( 164 ),
  613.            chr( 128 ),
  614.            "����"
  615.        ), array( "&#8364;", "&#8364;", "&#8364;" ), $str );
  616.        $str = str_replace( array(
  617.             chr( 165 ),
  618.             "�¥"
  619.         ), array( "&#165;", "&#165;" ), $str );
  620.         return $str;
  621.     }
  622.  
  623.     public function convertStr( $in_charset, $out_charset, $str )
  624.     {
  625.         if ( $out_charset == $in_charset || $in_charset == "" || $out_charset == "" )
  626.         {
  627.             return $str;
  628.         }
  629.         if ( function_exists( "iconv" ) )
  630.         {
  631.             $result = @iconv( $in_charset, $out_charset, $str );
  632.             if ( $result === FALSE )
  633.             {
  634.                 return $str;
  635.             }
  636.             return $result;
  637.         }
  638.         if ( $in_charset == "UTF-8" && $out_charset == "ISO-8859-1" )
  639.         {
  640.             return utf8_decode( $str );
  641.         }
  642.         if ( $in_charset == "ISO-8859-1" && $out_charset == "UTF-8" )
  643.         {
  644.             return utf8_encode( $str );
  645.         }
  646.         return $str;
  647.     }
  648.  
  649.     public function replaceCustomFields( &$db, $strEmailString, $userid, $dateFormat, $domainid = 0 )
  650.     {
  651.         require_once( "modules/clients/models/ObjectCustomFields.php" );
  652.         $query = "SELECT c.name,c.type,cv.value FROM customuserfields c, user_customuserfields cv where cv.customid=c.id and cv.userid=?";
  653.         $result = $db->query( $query, $userid );
  654.         while ( list( $tName, $tType, $tValue ) = $result->fetch() )
  655.         {
  656.             $tName = "[CUSTOMPROFILE_".$tName."]";
  657.             $tValue = NE_Lib::_parsecustomfieldtype( $tType, $tValue, $dateFormat );
  658.             $strEmailString = str_replace( $tName, $tValue, $strEmailString );
  659.         }
  660.         if ( $domainid != 0 )
  661.         {
  662.             $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." ";
  663.             $result = $db->query( $query, $domainid );
  664.             while ( list( $tName, $tType, $tValue ) = $result->fetch() )
  665.             {
  666.                 $tName = "[CUSTOMPACKAGE_".$tName."]";
  667.                 $tValue = NE_Lib::_parsecustomfieldtype( $tType, $tValue, $dateFormat );
  668.                 $strEmailString = str_replace( $tName, $tValue, $strEmailString );
  669.             }
  670.         }
  671.         $strEmailString = preg_replace( "/\\[CUSTOM.*\\]/U", "", $strEmailString );
  672.         return $strEmailString;
  673.     }
  674.  
  675.     public function _parseCustomFieldType( $type, $value, $dateFormat )
  676.     {
  677.         $newValue = "";
  678.         switch ( $type )
  679.         {
  680.         case typeYESNO :
  681.             if ( $value == 0 )
  682.             {
  683.                 $newValue = "No";
  684.                 return $newValue;
  685.             }
  686.             $newValue = "Yes";
  687.             return $newValue;
  688.         case TYPEDATE :
  689.             if ( $value != "" )
  690.             {
  691.                 break;
  692.             }
  693.             $newValue = NE_Lib::db_to_form( $value, $dateFormat, "/" );
  694.         }
  695.         $newValue = $value;
  696.         return $newValue;
  697.     }
  698.  
  699.     public function getCustomUserFieldIDForName( &$db, $name )
  700.     {
  701.         $query = "select id from customuserfields where name=?";
  702.         $result = $db->query( $query, $name );
  703.         list( $tID ) = $result->fetch();
  704.         return $tID;
  705.     }
  706.  
  707.     public function download( $str, $filename )
  708.     {
  709.         header( "Content-type: application/octet-stream" );
  710.         header( "Content-Disposition: attachment; filename=\"".$filename."\"" );
  711.         header( "Content-Length: ".strlen( $str ) );
  712.         header( "Pragma: public" );
  713.         header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  714.         header( "Expires: 0" );
  715.         echo $str;
  716.         exit();
  717.     }
  718.  
  719.     public function getBasicConfiguration( $frameworkConfig, $hostname, $dbuser, $dbpass, $database, $dbEncoding, $sessionName )
  720.     {
  721.         $configuration = array(
  722.             "framework" => array(
  723.                 "appName" => $frameworkConfig['appName'],
  724.                 "appVersion" => $frameworkConfig['appVersion'],
  725.                 "appVersions" => $frameworkConfig['appVersions'],
  726.                 "errorLevel" => $frameworkConfig['errorLevel'],
  727.                 "displayErrors" => $frameworkConfig['displayErrors'],
  728.                 "dbEngine" => $frameworkConfig['dbEngine'],
  729.                 "dbDefaultEncoding" => $frameworkConfig['dbDefaultEncoding'],
  730.                 "defaultLanguage" => $frameworkConfig['defaultLanguage'],
  731.                 "defaultCharSet" => $frameworkConfig['defaultCharSet'],
  732.                 "defaultTemplate" => $frameworkConfig['defaultTemplate'],
  733.                 "defaultModule" => $frameworkConfig['defaultModule'],
  734.                 "defaultModule_Mobile" => $frameworkConfig['defaultModule_Mobile'],
  735.                 "hooksPublicSection" => $frameworkConfig['hooksPublicSection'],
  736.                 "specialConfigurations" => $frameworkConfig['specialConfigurations'],
  737.                 "pluginTypes" => $frameworkConfig['pluginTypes'],
  738.                 "maskInLog" => $frameworkConfig['maskInLog']
  739.             ),
  740.             "application" => array(
  741.                 "dbHostname" => $hostname,
  742.                 "dbUser" => $dbuser,
  743.                 "dbPassword" => $dbpass,
  744.                 "dbSchema" => $database,
  745.                 "dbEncoding" => $dbEncoding,
  746.                 "sessionName" => $sessionName,
  747.                 "installed" => INSTALLED,
  748.                 "logLevel" => defined( "LOG_LEVEL" ) ? LOG_LEVEL : NULL,
  749.                 "logScreen" => defined( "LOG_SCREEN" ) ? LOG_SCREEN : NULL,
  750.                 "logTextFile" => defined( "LOG_TEXTFILE" ) ? LOG_TEXTFILE : NULL
  751.             ),
  752.             "modules" => array()
  753.         );
  754.         return $configuration;
  755.     }
  756.  
  757.     public static function getModulesConfiguration( $currentConfiguration, $getInstalledVersion = FALSE )
  758.     {
  759.         $configuration = array();
  760.         $db =& NE_Registry::getdatabase();
  761.         if ( isset( $_SESSION['moduleconfigs'] ) )
  762.         {
  763.             $configuration = unserialize( $_SESSION['moduleconfigs'] );
  764.             return $configuration;
  765.         }
  766.         if ( !is_a( $db, "NE_Error" ) || $getInstalledVersion )
  767.         {
  768.             $installedModules = array();
  769.             $query = "SELECT module, version FROM versions";
  770.             $db->setSkipFatalError( TRUE );
  771.             $result = $db->query( $query );
  772.             $db->setSkipFatalError( FALSE );
  773.             while ( !is_a( $result, "NE_Error" ) || ( $row = $result->fetch() ) )
  774.             {
  775.                 $installedModules[$row['module']] = $row['version'];
  776.             }
  777.         }
  778.         include( "newedge/config.php" );
  779.         $configuration['newedge'] = $config;
  780.         if ( isset( $installedModules['newedge'] ) )
  781.         {
  782.             $configuration['newedge']['installedVersion'] = $installedModules['newedge'];
  783.         }
  784.         $modulesPath = realpath( dirname( __FILE__ )."/../../modules" );
  785.         $dir = dir( $modulesPath );
  786.         for ( ; while ( FALSE !== ( $entry = $dir->read() ) )
  787.  {
  788.  if ( isset( $currentConfiguration['framework']['specialConfigurations'][$entry] ) )
  789.  {
  790.  $configFileName = $currentConfiguration['framework']['specialConfigurations'][$entry], }
  791.  else
  792.  {
  793.  $configFileName = "config.php", }
  794.  if ( in_array( $entry, array( ".", "..", "CVS", ".svn" ) ) )
  795.  {
  796.  break;
  797.  }
  798.  is_dir( "{$modulesPath}/{$entry}" ) && is_readable( "{$modulesPath}/{$entry}/{$configFileName}" ); }
  799.  )
  800.         {
  801.             include( "{$modulesPath}/{$entry}/{$configFileName}" );
  802.             $configuration[$entry] = $config;
  803.             if ( isset( $installedModules[$entry] ) )
  804.             {
  805.                 $configuration[$entry]['installedVersion'] = $installedModules[$entry];
  806.             }
  807.         }
  808.         uasort( &$configuration, array( "NE_Lib", "_sortConfig" ) );
  809.         $_SESSION['moduleconfigs'] = serialize( $configuration );
  810.         return $configuration;
  811.     }
  812.  
  813.     public function getOldFrameworkAppVersion()
  814.     {
  815.         $db =& NE_Registry::getdatabase();
  816.         $configuration = NE_Registry::getconfiguration();
  817.         if ( !is_a( $db, "NE_Error" ) )
  818.         {
  819.             $query = "SELECT value FROM `setting` WHERE name=?";
  820.             $result = @$this->db->query( $query, $configuration['framework']['appName']." Version" );
  821.             list( $version ) = $result->fetch();
  822.             if ( $version )
  823.             {
  824.                 return $version;
  825.             }
  826.         }
  827.         return FALSE;
  828.     }
  829.  
  830.     public function _sortConfig( $a, $b )
  831.     {
  832.         if ( $a == "newedge" || $a['order'] < $b['order'] )
  833.         {
  834.             return -1;
  835.         }
  836.         if ( $b == "newedge" || $b['order'] < $a['order'] )
  837.         {
  838.             return 1;
  839.         }
  840.         return 0;
  841.     }
  842.  
  843.     public function _array_map_recursive( $func, $arr )
  844.     {
  845.         $newArr = array();
  846.         foreach ( $arr as $key => $value )
  847.         {
  848.             if ( is_array( $value ) )
  849.             {
  850.                 $newArr[$key] = NE_Lib::_array_map_recursive( $func, $value );
  851.             }
  852.             else if ( is_array( $func ) && is_string( $func[0] ) )
  853.             {
  854.                 $newArr[$key] = call_user_func( array(
  855.                     $func[0],
  856.                     $func[1]
  857.                 ), $value );
  858.             }
  859.             else if ( is_array( $func ) && is_object( $func[0] ) )
  860.             {
  861.                 $newArr[$key] = $func[0]->$func[1]( $value );
  862.             }
  863.             else
  864.             {
  865.                 $newArr[$key] = $func( $value );
  866.             }
  867.         }
  868.         return $newArr;
  869.     }
  870.  
  871.     public function encryptData( $text, $key )
  872.     {
  873.         if ( !extension_loaded( "mcrypt" ) )
  874.         {
  875.             ( "Error: you don't have the mcrypt extension enabled" );
  876.             return new NE_Error();
  877.         }
  878.         $iv_size = mcrypt_get_iv_size( MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB );
  879.         $iv = mcrypt_create_iv( $iv_size, MCRYPT_RAND );
  880.         $crypttext = mcrypt_encrypt( MCRYPT_TRIPLEDES, $key, $text, MCRYPT_MODE_ECB, $iv );
  881.         return $crypttext;
  882.     }
  883.  
  884.     public function decryptData( $text, $key )
  885.     {
  886.         if ( !extension_loaded( "mcrypt" ) )
  887.         {
  888.             ( "Error: you don't have the mcrypt extension enabled" );
  889.             return new NE_Error();
  890.         }
  891.         $iv_size = mcrypt_get_iv_size( MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB );
  892.         $iv = mcrypt_create_iv( $iv_size, MCRYPT_RAND );
  893.         $decrypttext = mcrypt_decrypt( MCRYPT_TRIPLEDES, $key, $text, MCRYPT_MODE_ECB, $iv );
  894.         return rtrim( $decrypttext );
  895.     }
  896.  
  897.     public function getExecutable( $locations )
  898.     {
  899.         if ( strtoupper( mb_substr( PHP_OS, 0, 3 ) ) == "WIN" )
  900.         {
  901.             return FALSE;
  902.         }
  903.         foreach ( $locations as $location )
  904.         {
  905.             if ( !@is_executable( $location ) )
  906.             {
  907.                 continue;
  908.             }
  909.             return $location;
  910.         }
  911.         return FALSE;
  912.     }
  913.  
  914.     public static function redirectPage( $redirectURL, $message = "", $extraVarsArr = FALSE )
  915.     {
  916.         $redirectURL = str_replace( "&", "&", $redirectURL );
  917.         $extraVars = array();
  918.         if ( $extraVarsArr )
  919.         {
  920.             foreach ( $extraVarsArr as $varName => $varValue )
  921.             {
  922.                 $extraVars[] = "{$varName}={$varValue}";
  923.             }
  924.         }
  925.         if ( $extraVars )
  926.         {
  927.             if ( strpos( $redirectURL, "?" ) !== FALSE )
  928.             {
  929.                 $extraVarsStr = "&";
  930.             }
  931.             else
  932.             {
  933.                 $extraVarsStr = "?";
  934.             }
  935.             $extraVarsStr .= implode( "&", $extraVars );
  936.         }
  937.         else
  938.         {
  939.             $extraVarsStr = "";
  940.         }
  941.         if ( $message )
  942.         {
  943.             NE_Lib::addmessage( $message );
  944.         }
  945.         header( "Location: ".$redirectURL.$extraVarsStr );
  946.         exit();
  947.     }
  948.  
  949.     public function addMessage( $message )
  950.     {
  951.         if ( !isset( $_SESSION['messages'] ) )
  952.         {
  953.             return;
  954.         }
  955.         if ( is_array( $message ) )
  956.         {
  957.             $_SESSION['messages'] = array_merge( $_SESSION['messages'], $message );
  958.         }
  959.         else
  960.         {
  961.             $_SESSION['messages'][] = $message;
  962.         }
  963.     }
  964.  
  965.     public function showErrorMsg( $errorEnum, &$user, $templateName, $returnHTML = FALSE )
  966.     {
  967.         $text = "<table><tr><td valign=middle><font color=red>";
  968.         switch ( $errorEnum )
  969.         {
  970.         case errDuplicateEmail :
  971.             $text .= "That E-mail is already in use, please make the appropriate changes and re-submit.";
  972.             break;
  973.         case errDuplicateDomainName :
  974.             $text .= "That Domain is already in use, please make the appropriate changes and re-submit.";
  975.             break;
  976.         case errDuplicateUserName :
  977.             $text .= "That Username is already in use, please make the appropriate changes and re-submit.";
  978.             break;
  979.         case ERRINCORRECTPASSPHRASE :
  980.             $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";
  981.             break;
  982.         case errCCExpiresInPast :
  983.             $text .= $user->lang( "The credit card has already expired" );
  984.             break;
  985.         case errUsersLimitReached :
  986.             $text .= $user->lang( "You have reached your number of users limit" );
  987.         }
  988.         $text .= "</font></td></tr></table>";
  989.         if ( $returnHTML )
  990.         {
  991.             return $text;
  992.         }
  993.         echo $text;
  994.     }
  995.  
  996.     public function isPassphraseLimbo( &$db )
  997.     {
  998.         $query = "select id from users where updating=1 and passphrased=1";
  999.         $result = $db->query( $query );
  1000.         $num = $result->fetch();
  1001.         if ( 0 < $num )
  1002.         {
  1003.             return TRUE;
  1004.         }
  1005.         return FALSE;
  1006.     }
  1007.  
  1008.     public function decodehtmlspecialchars( $text )
  1009.     {
  1010.         if ( function_exists( "htmlspecialchars_decode" ) )
  1011.         {
  1012.             return htmlspecialchars_decode( $text );
  1013.         }
  1014.         return strtr( $text, array_flip( get_html_translation_table( HTML_SPECIALCHARS ) ) );
  1015.     }
  1016.  
  1017.     public function processXML( $dataArray, $level = 1, $startTag = "array" )
  1018.     {
  1019.         $xml = "";
  1020.         if ( $level == 1 )
  1021.         {
  1022.             $xml .= "<".$startTag.">\n";
  1023.         }
  1024.         foreach ( $dataArray as $key => $value )
  1025.         {
  1026.             $key = strtolower( $key );
  1027.             if ( is_object( $value ) )
  1028.             {
  1029.                 $value = get_object_vars( $value );
  1030.             }
  1031.             if ( is_array( $value ) )
  1032.             {
  1033.                 $multi_tags = FALSE;
  1034.                 foreach ( $value as $key2 => $value2 )
  1035.                 {
  1036.                     if ( is_object( $value2 ) )
  1037.                     {
  1038.                         $value2 = get_object_vars( $value2 );
  1039.                     }
  1040.                     if ( is_array( $value2 ) )
  1041.                     {
  1042.                         $xml .= str_repeat( "\t", $level ).( "<".$key.">\n" );
  1043.                         $xml .= NE_Lib::processxml( $value2, $level + 1 );
  1044.                         $xml .= str_repeat( "\t", $level ).( "</".$key.">\n" );
  1045.                         $multi_tags = TRUE;
  1046.                     }
  1047.                     else
  1048.                     {
  1049.                         if ( trim( $value2 ) != "" )
  1050.                         {
  1051.                             if ( htmlspecialchars( $value2 ) != $value2 )
  1052.                             {
  1053.                                 $xml .= str_repeat( "\t", $level ).( "<".$key2."><![CDATA[{$value2}]]>" ).( "</".$key2.">\n" );
  1054.                             }
  1055.                             else
  1056.                             {
  1057.                                 $xml .= str_repeat( "\t", $level ).( "<".$key2.">{$value2}</{$key2}>\n" );
  1058.                             }
  1059.                         }
  1060.                         $multi_tags = TRUE;
  1061.                     }
  1062.                 }
  1063.                 if ( !$multi_tags )
  1064.                 {
  1065.                     if ( 0 < count( $value ) )
  1066.                     {
  1067.                         $xml .= str_repeat( "\t", $level ).( "<".$key.">\n" );
  1068.                         $xml .= NE_Lib::processxml( $value, $level + 1 );
  1069.                         $xml .= str_repeat( "\t", $level ).( "</".$key.">\n" );
  1070.                     }
  1071.                 }
  1072.             }
  1073.             else if ( trim( $value ) != "" )
  1074.             {
  1075.                 if ( htmlspecialchars( $value ) != $value )
  1076.                 {
  1077.                     $xml .= str_repeat( "\t", $level ).( "<".$key.">" ).( "<![CDATA[".$value."]]></{$key}>\n" );
  1078.                 }
  1079.                 else
  1080.                 {
  1081.                     $xml .= str_repeat( "\t", $level ).( "<".$key.">{$value}</{$key}>\n" );
  1082.                 }
  1083.             }
  1084.         }
  1085.         if ( $level == 1 )
  1086.         {
  1087.             $xml .= "</".$startTag.">\n";
  1088.         }
  1089.         return $xml;
  1090.     }
  1091.  
  1092. }
  1093.  
  1094. if ( !function_exists( "json_encode" ) )
  1095. {
  1096.     require_once( "newedge/classes/Services/JSON.php" );
  1097.     function json_encode( $a )
  1098.     {
  1099.         ();
  1100.         $json = new Services_JSON();
  1101.         return $json->encode( $a );
  1102.     }
  1103. }
  1104. if ( !function_exists( "json_decode" ) )
  1105. {
  1106.     require_once( "newedge/classes/Services/JSON.php" );
  1107.     function json_decode( $a )
  1108.     {
  1109.         ();
  1110.         $json = new Services_JSON();
  1111.         return $json->decode( $a );
  1112.     }
  1113. }
  1114. if ( !function_exists( "mb_substr_replace" ) )
  1115. {
  1116.     function mb_substr_replace( $string, $replacement, $start, $length = NULL, $encoding = "UTF-8" )
  1117.     {
  1118.         if ( $encoding == NULL )
  1119.         {
  1120.             if ( $length == NULL )
  1121.             {
  1122.                 return mb_substr( $string, 0, $start ).$replacement;
  1123.             }
  1124.             return mb_substr( $string, 0, $start ).$replacement.mb_substr( $string, $start + $length );
  1125.         }
  1126.         if ( $length == NULL )
  1127.         {
  1128.             return mb_substr( $string, 0, $start, $encoding ).$replacement;
  1129.         }
  1130.         return mb_substr( $string, 0, $start, $encoding ).$replacement.mb_substr( $string, $start + $length, mb_strlen( $string, $encoding ), $encoding );
  1131.     }
  1132. }
  1133. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement