[Phpsysinfo-subversion] SF.net SVN: phpsysinfo:[217] includes/class.CommonFunctions.inc.php
Brought to you by:
namiltd
From: <big...@us...> - 2009-05-25 08:54:55
|
Revision: 217 http://phpsysinfo.svn.sourceforge.net/phpsysinfo/?rev=217&view=rev Author: bigmichi1 Date: 2009-05-25 08:54:48 +0000 (Mon, 25 May 2009) Log Message: ----------- formatting Modified Paths: -------------- includes/class.CommonFunctions.inc.php Modified: includes/class.CommonFunctions.inc.php =================================================================== --- includes/class.CommonFunctions.inc.php 2009-05-25 08:52:56 UTC (rev 216) +++ includes/class.CommonFunctions.inc.php 2009-05-25 08:54:48 UTC (rev 217) @@ -25,9 +25,13 @@ */ class CommonFunctions { - + /** + * phpSysInfo version + * + * @var string + */ const PSI_VERSION = '3.0-rc6'; - + /** * Find a system program, do also path checking when not running on WINNT * on WINNT we simply return the name with the exe extension to the program name @@ -36,23 +40,23 @@ * * @return string complete path and name of the program */ - private static function _findProgram($strProgram) + private static function _findProgram($strProgram) { - $arrPath = array ('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin'); + $arrPath = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin'); if (PSI_ADD_PATHS !== false) { $addpaths = explode(',', PSI_ADD_PATHS); $arrPath = array_merge($addpaths, $arrPath); // In this order so $addpaths is before $arrPath when looking for a program } - // If open_basedir defined, fill the $open_basedir array with authorized paths,. (Not tested when no open_basedir restriction) - if ((bool) ini_get('open_basedir')) { - $open_basedir = explode(':', ini_get('open_basedir')); - } + // If open_basedir defined, fill the $open_basedir array with authorized paths,. (Not tested when no open_basedir restriction) + if ((bool)ini_get('open_basedir')) { + $open_basedir = explode(':', ini_get('open_basedir')); + } if (PHP_OS != 'WINNT') { foreach ($arrPath as $strPath) { - // To avoid "open_basedir restriction in effect" error when testing paths if restriction is enabled - if (($open_basedir && !in_array($strPath, $open_basedir)) || !is_dir($strPath)) { - continue; - } + // To avoid "open_basedir restriction in effect" error when testing paths if restriction is enabled + if (($open_basedir && !in_array($strPath, $open_basedir)) || !is_dir($strPath)) { + continue; + } $strProgrammpath = $strPath."/".$strProgram; if (is_executable($strProgrammpath)) { return $strProgrammpath; @@ -62,7 +66,7 @@ return $strProgram.'.exe'; } } - + /** * Execute a system program. return a trim()'d result. * does very crude pipe checking. you need ' | ' for it to work @@ -76,11 +80,11 @@ * * @return boolean command successfull or not */ - public static function executeProgram($strProgramname, $strArgs, & $strBuffer, $booErrorRep = true) + public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true) { $strBuffer = ''; $strError = ''; - $pipes = array (); + $pipes = array(); $strProgram = self::_findProgram($strProgramname); $error = Error::singleton(); if (!$strProgram) { @@ -100,7 +104,7 @@ } } } - $descriptorspec = array (0=> array ("pipe", "r"), 1=> array ("pipe", "w"), 2=> array ("pipe", "w")); + $descriptorspec = array(0=>array("pipe", "r"), 1=>array("pipe", "w"), 2=>array("pipe", "w")); $process = proc_open($strProgram." ".$strArgs, $descriptorspec, $pipes); if (is_resource($process)) { $strBuffer .= self::_timeoutfgets($pipes, $strBuffer, $strError); @@ -122,7 +126,7 @@ } return true; } - + /** * find duplicate entrys and count them, show this value befor the duplicated name * @@ -132,7 +136,7 @@ */ public static function finddups($arrInput) { - $arrResult = array (); + $arrResult = array(); if (is_array($arrInput)) { $arrBuffer = array_count_values($arrInput); foreach ($arrBuffer as $strKey=>$intValue) { @@ -145,7 +149,7 @@ } return $arrResult; } - + /** * read a file and return the content as a string * @@ -157,7 +161,7 @@ * * @return boolean command successfull or not */ - public static function rfts($strFileName, & $strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true) + public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true) { $strFile = ""; $intCurLine = 1; @@ -188,7 +192,7 @@ } return true; } - + /** * reads a directory and return the name of the files and directorys in it * @@ -199,7 +203,7 @@ */ public static function gdc($strPath, $booErrorRep = true) { - $arrDirectoryContent = array (); + $arrDirectoryContent = array(); $error = Error::singleton(); if (is_dir($strPath)) { if ($handle = opendir($strPath)) { @@ -221,7 +225,7 @@ } return $arrDirectoryContent; } - + /** * Check for needed php extensions * @@ -235,8 +239,8 @@ */ public static function checkForExtensions() { - // TODO XSL extension is only required in case there is no javascript, we'd better test this extension in this case only to improve compatibility - $extensions = array ('simplexml', 'pcre', 'xml', 'xsl', 'mbstring'); + // TODO XSL extension is only required in case there is no javascript, we'd better test this extension in this case only to improve compatibility + $extensions = array('simplexml', 'pcre', 'xml', 'xsl', 'mbstring'); $text = ""; $error = false; $text .= "<?xml version='1.0'?>\n"; @@ -254,12 +258,11 @@ if ($error) { header("Content-Type: text/xml\n\n"); echo $text; - die (); + die(); } } + - - /** * get the content of stdout/stderr with the option to set a timeout for reading * @@ -270,12 +273,12 @@ * * @return void */ - private static function _timeoutfgets($pipes, & $out, & $err, $sek = 2) + private static function _timeoutfgets($pipes, &$out, &$err, $sek = 2) { // fill output string $time = $sek; while ($time >= 0) { - $read = array ($pipes[1]); + $read = array($pipes[1]); while (!feof($read[0]) && ($n = stream_select($read, $w = null, $e = null, $time)) !== false && $n > 0 && strlen($c = fgetc($read[0])) > 0) { $out .= $c; } @@ -284,14 +287,14 @@ // fill error string $time = $sek; while ($time >= 0) { - $read = array ($pipes[2]); + $read = array($pipes[2]); while (!feof($read[0]) && ($n = stream_select($read, $w = null, $e = null, $time)) !== false && $n > 0 && strlen($c = fgetc($read[0])) > 0) { $err .= $c; } --$time; } } - + /** * get all configured plugins from config.php (file must be included before calling this function) * @@ -299,7 +302,7 @@ */ public static function getPlugins() { - $plugins = preg_split("/[\s]?,[\s]?/", PSI_PLUGINS, - 1, PREG_SPLIT_NO_EMPTY); + $plugins = preg_split("/[\s]?,[\s]?/", PSI_PLUGINS, -1, PREG_SPLIT_NO_EMPTY); return $plugins; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |