/** Loads a PHP-extension. */ function knj_dl($extension){ if (is_array($extension)){ foreach($extension AS $ext){ knj_dl($ext); } return true; } require_once "knj/functions_knj_os.php"; $pre = ""; $os = knj_os::getOS(); if (extension_loaded($extension)){ return true; } if ($extension == "sqlite" && !extension_loaded("php_pdo")){ knj_dl("pdo"); } if ($os["os"] == "windows"){ $pre = "php_"; $app = ".dll"; if ($extension == "glade" || $extension == "libglade"){ $extension = "gtk_libglade2"; }elseif($extension == "gd"){ $extension = "gd2"; } }else{ $app = ".so"; if ($extension == "gtk2"){ $pre = "php_"; } } if ($extension == "gtk2" && extension_loaded("php-gtk")){ return true; } if (!ini_get("enable_dl")){ throw new Exception("The option \"enable_dl\" is not enabled in \"php.ini\" - cant load extension."); } if (!dl($pre . $extension . $app)){ throw new Exception("Could not load the extension: " . $extension . "."); } return true; }
/** Returns information about a specific networking-device. */ function network_ifconfig($args = null){ //Make ifconfig-command. if (is_string($args)){ $command = "ifconfig " . $device; }else{ $command = "ifconfig"; } //Run command and catch result. if ($args["output"]){ $ipconfig = $args["output"]; }else{ $os = knj_os::getOS(); if ($os["os"] != "linux"){ throw new Exception("This command only works with Linux."); } $ipconfig = knj_os::shellCMD($command); $ipconfig = $ipconfig["result"]; } //Parse result. if (preg_match_all("/([a-z]+[0-9]{0,2})\s+Link encap([\s\S]+)(\n\n|\r\n\r\n)/U", $ipconfig, $matches)){ foreach($matches[0] AS $key => $device_out){ $interface = $matches[1][$key]; if (preg_match_all("/(R|T)X bytes:([0-9]+)/", $device_out, $match_bytes)){ $return[$interface]["rx_bytes"] = $match_bytes[2][0]; $return[$interface]["tx_bytes"] = $match_bytes[2][1]; } if (preg_match("/inet addr:([0-9.]{7,15})/", $device_out, $match_ip)){ $return[$interface]["ip"] = $match_ip[1]; } if (preg_match("/Mask:([0-9.]{7,15})/", $device_out, $match_ip)){ $return[$interface]["mask"] = $match_ip[1]; } if (preg_match("/Bcast:([0-9.]{7,15})/", $device_out, $match_ip)){ $return[$interface]["bast"] = $match_ip[1]; } } } return $return; }
/** This function handels the locales-command on Linux-systems in an easy way. */ function knj_locate($string){ require_once("knj/functions_knj_os.php"); require_once("knj/functions_knj_strings.php"); //Error handeling. $os = knj_os::getOS(); if ($os["os"] != "linux"){ throw new Exception("This function only works on Linux."); } //Make shell-command. $cmd = "locate"; if (is_array($string)){ foreach($string AS $str){ $cmd .= " " . knj_string_unix_safe($str); } }else{ $cmd .= " " . knj_string_unix_safe($string); } //Execute shell-command. $result = knj_os::shellCMD($cmd); if (strlen(trim($result["error"]))){ throw new Exception($result["error"]); } //Make array of files found and unset the last one (because it will be empty). $files = explode("\n", $result["result"]); unset($files[count($files) - 1]); //Return the array. return $files; }
$renames[$file] = $file_new; } } foreach($renames AS $key => $value){ if (rename($folder . "/" . $key, $folder . "/" . $value)){ $this->tv_files->get_model()->append(array($value)); }else{ $this->tv_files->get_model()->append(array($key)); } } } } //Start program. require_once("knjphpframework/functions_knj_extensions.php"); require_once("knjphpframework/functions_knj_os.php"); require_once("knjphpframework/functions_treeview.php"); if (!knj_dl("gtk2")){ die("Could not load PHP-GTK2-module.\n"); } if (knj_os::getOS() == "windows"){ //Set Windows-skin if running Windows. Gtk::rc_parse("gtkrc"); } $win_main = new WinMain(); Gtk::main(); ?>
/** Returns the path to the PHP-executable, which you need if you want to start new processes. */ static function getPHPExec($version = 5){ $os = knj_os::getOS(); if ($os["os"] == "linux"){ $test_paths = array( "/usr/bin/php" . $version, "/usr/local/bin/php" . $version, "/usr/bin/php", "/usr/local/bin/php" ); foreach($test_paths AS $path){ if (file_exists($path)){ return $path; } } if ($_SERVER["_"] && file_exists($_SERVER["_"])){ return $_SERVER["_"]; } }elseif($os["os"] == "windows"){ //A hack to make this function work with packages created with knjPackageCreater. if (file_exists("../php5gtk2/php.exe")){ return realpath("../php5gtk2/php.exe"); } }else{ throw new Exception("Unsupported OS: \"" . $os["os"] . "\"."); } throw new Exception("Could not find the PHP-executable."); }
/** Parse a string so it will be a valid filename. */ function knj_string_filename($string, $os = null){ if (!$os){ require_once("knj/os.php"); $os = knj_os::getOS(); $os = $os["os"]; } if ($os == "windows"){ //parse windows-filename here. }elseif($os == "linux"){ $string = strtr($string, array( "å" => "aa", "ø" => "oe", "æ" => "ae", utf8_decode("å") => "aa", utf8_decode("æ") => "ae", utf8_decode("ø") => "oe", "|" => "", "&" => "", "/" => "", "\\" => "" )); }else{ throw new Exception("Unsupported OS."); } return $string; }