⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 install.inc

📁 用来优化php载入速度
💻 INC
📖 第 1 页 / 共 5 页
字号:
				else{					$this->msgbox("File: \"$file\" doesn't exist!");				}			}			else{				break;			}		}		return $file;	}		// SELECT_FILE	function select_file($msg, $default="", $accept_empty=false)	{		return $this->strip_symlink ($this->select_file_nostrip($msg, $default, $accept_empty));	}		// CHOOSE_DIR	function choose_dir($msg, $default, $min_space_size=0, $illegal_chars=" \;\$\#\'\"")	{		while(true){			$dir = $this->inputbox($msg, $default);			$dir = $this->expand_tilde($dir);			if(file_exists($dir)) {				$dir = $this->strip_symlink($dir);			}			if(!preg_match("/^\//", $dir)){				$this->msgbox("The path must be absolute!");			}			else if($illegal_chars && preg_match("/[".$illegal_chars."]/", $dir)) {				$chars_str = implode(",", preg_split("//", trim(stripslashes($illegal_chars)), -1, PREG_SPLIT_NO_EMPTY));				if($chars_str != "") {					$chars_str = ": $chars_str and";				}				$chars_str .= " the whitespace character";				$this->msgbox("The path contains illegal characters!\n"					."It must not contain".addslashes($chars_str).".");			}			else{				$dir = $this->nice_path($dir);				if($min_space_size != 0) {					$install_target = $dir;					while(strlen($install_target) > 1 && !$this->my_dir_exists($install_target)) {						$install_target = $this->my_dirname($install_target);					}					$actual_free_space = disk_free_space($install_target);					if($actual_free_space < $min_space_size) {					  $this->logger->log ("Directory $dir has a free disk space: " .							     $this->size_human ($actual_free_space) . 							     ' , but at least ' . 							     $this->size_human ($min_space_size) . 							     ' is needed');					  $this->msgbox("The directory must have at least ".$this->size_human($min_space_size).								" of free disk space.\nPlease provide another directory.");						continue;					}				}				break;			}		}		return $dir;	}	// FSELECT	function fselect ($path="/", $msg=null)	{		$this->progress_bar_stop();		if (isset ($this->conf['dialog'])) {			$file = $this->rundialog ('fselect', $path);		} else {			$file = $this->select_file ($msg, $file);		}		return $file;	}		// CHOOSE_PREFIX	function choose_prefix($what, $default, $min_space_size=0, $illegal_chars=" \;\$\#\'\"")	{		return $this->choose_dir("Please specify the location for installing $what:\n", $default,			$min_space_size, $illegal_chars);	}	// CHOOSE_INSTALL_PREFIX	function choose_install_prefix($default)	{		if(isset($this->conf['default_prefix'])) {			if(!$this->conf['interactive']) {				return;			}			$default = $this->conf['default_prefix'];		}		$this->logger->log ('Choosing install prefix ...');		$this->conf['prefix'] = $this->choose_prefix($this->conf['product'], $default,				isset($this->conf['min_space_size']) ? $this->conf['min_space_size'] : 0);		$this->conf['saved_config']['default_prefix'] = $this->conf['prefix'];	}	// USER2UID	function user2uid($user)	{		$pw = posix_getpwnam($user);		return $pw["uid"];	}	// UID2USER	function uid2user ($uid)	{		$userinfo = @posix_getpwuid($uid);		if($userinfo !== false) {			return $userinfo["name"];		}		return false;	}	// LINK_STARTUP_DAEMON	/* program must understand 'start' and 'stop' arguments */	function link_startup_daemon($script, $name=null, $descr=null)	{		if (!$name) {			$name = basename($script);			$name = preg_replace ('@\..*$@', '', $name);		}		if (!$descr) {			$descr = $name;		}		$err = null;		if (@file_exists ('/etc/gentoo-release')) {			$init_script = <<<EOF#!/sbin/runscriptdepend() {	need net}start() {	{$script} start}stop() {	{$script} stop} restart() {	{$script} restart}EOF;			$target_script = "/etc/init.d/{$name}.Zend";			$this->str2file ($init_script, $target_script);			$this->set_permissions ($target_script, "0755");			$cmd = "rc-update add {$name}.Zend default";			if ($this->run_command ("{$cmd} 1>/dev/null") != 0) {				$err = "Cannot run: {$cmd}";			}		}		else if (PHP_OS == "Linux" || PHP_OS == "SunOS") {			// Detect default init level to determine the RC directory where to install the script			if(preg_match ('/(\d+):initdefault/', $this->file2str('/etc/inittab'), $match)) {				$rc_dir = '/etc/rc'.$match[1].'.d';				if (!$this->my_dir_exists ($rc_dir)) {					$rc_dir = '/etc/init.d/rc'.$match[1].'.d';				}				if (!$this->my_dir_exists ($rc_dir)) {					$rc_dir = '/etc/rc.d/rc'.$match[1].'.d';				}			}			if (isset ($rc_dir)) {				$target_script = $rc_dir.'/S'.$name.".Zend";				if (!$this->my_symlink ($script, $target_script)) {					$err = "Cannot symlink {$target_script} to {$script}";				}			} else {				$err = "Cannot find init scripts directory";			}		}		else if (PHP_OS == "FreeBSD") {			$rc_dir = '/usr/local/etc/rc.d';			$target_script = $rc_dir.'/S'.$name.".Zend.sh";			if (!$this->my_symlink ($script, $target_script)) {				$err = "Cannot symlink {$target_script} to {$script}";			}		}		else if (PHP_OS == "Darwin") {			$rc_dir = '/Library/StartupItems/Zend'.$name;			if(!$this->my_mkdir_long ($rc_dir)) {				$err = "Cannot create directory {$rc_dir}";			}	                        $this->my_copy ($script, '/Library/StartupItems/Zend'.$name.'/'.basename($script));                        $this->str2file (                                "{\n".                                "       Description     = \"$descr\";\n".                                "       Provides        = (\"$script\");\n".				"       Requires        = (\"Network\");\n".                                "       OrderPreference = \"None\";\n".                                "       Messages =\n".                                "       {\n".                                "               start = \"Starting $name\";\n".                                "               stop  = \"Stopping $name\";\n".                                "       };\n".                                "}",                                '/Library/StartupItems/Zend'.$name.'/StartupParameters.plist');		} else{			$err = "Automatic loading is not supported for this platform";		}		if ($err !== null) {			$this->msgbox (				"Cannot register $script to start automatically when the system boots\n\n".				"ERROR: {$err}\n\n".				"You will have to fix this problem after the installation is complete"			);		}	}	// CONSTRUCT_CRONTAB_LINE	function construct_crontab_line($min_frequency, $args)	{		if($min_frequency <= 0 || $min_frequency > 60){		  $this->on_error ('Frequency must be in range between 1 and 60');		}		$crontab_line = "";		for($i=0; $i<60; $i += $min_frequency){			$crontab_line .= "$i";			if($i < 60-$min_frequency){				$crontab_line .= ",";			}		}		$crontab_line .= " * * * *  $args";		$this->logger->log ("Constructing a crontab line: $crontab_line");		return $crontab_line;	}		// --------------------------	// FILE FUNCTIONS	// ==========================	// MY_MOVE	function my_move($oldname, $newname, $delete=false)	{		if($delete){ /* delete destination before moving */			$this->my_delete($newname);		}		$this->my_mkdir_long (dirname($newname));		if($this->my_file_exists($this->strip_symlink($oldname))){			$this->logger->log ("Moving: $oldname to: $newname");			return @rename($oldname, $newname);		}		else if($this->my_dir_exists($oldname)){			$this->my_dir_move($oldname, $newname);		}		else{		  $this->on_error 		    ("Cannot rename file: \"$oldname\" (it's neither a file nor a directory).");		}	}	// MY_DIR_MOVE	function my_dir_move($oldname, $newname)	{		if(!$this->my_dir_exists($oldname)){		  $this->on_error ("File: $oldname should be a directory.");		}		$this->run_command("mv $oldname $newname");	}	// MY_TOUCH	function my_touch($file)	{		$dir = dirname($file);		if(!$this->my_dir_exists($dir)){			$this->my_mkdir_long($dir);		}		if(!$this->my_file_exists($file)){			$this->logger->log ("Creating file: $file");			if(!$this->run_silently("touch", $file)){			  $this->on_error ("Cannot create file: $file");			}		}	}	// MY_COPY	function my_copy ($oldname, $newname, $follow_symlinks=true, $overrite=true)	{		if($this->my_dir_exists($newname)){			$newname = $newname.$this->conf['slash'].basename($oldname);		}		if ($this->my_file_exists ($newname)) {		  if (! $overrite)		    {		      $this->logger->log ("Not overriting $newname with $oldname");		      return;		    }			$this->my_rename ($newname, "$newname.old", false);			$this->my_unlink ("$newname.old", false); // Unlink the old file		} else {			$this->my_delete ($newname);		}		$this->my_mkdir_long (dirname($newname));		if (!$follow_symlinks && $this->my_link_exists($oldname)) {			$dest = readlink ($oldname);			if ($dest !== false) {				$this->my_symlink ($dest, $newname);			}		}		else if($this->my_file_exists($this->strip_symlink($oldname))){			$perms = fileperms($oldname);			$owner = fileowner($oldname);			$group = filegroup($oldname);			if(!$this->my_is_writable($newname)){				$this->infobox("Cannot overwrite: $newname");			}			else{				if (!$this->run_silently("copy", $oldname, $newname)) {					$this->infobox("Cannot copy: $oldname to: $newname");				}				else{					$this->logger->log ("Copying: $oldname to: $newname");					$this->set_permissions($newname, decoct($perms), $owner, $group);				}			}		}		else if($this->my_dir_exists($oldname)){			$this->my_dir_copy($oldname, $newname, $follow_symlinks);		}		else{		  $this->on_error		    ("Cannot copy file: \"$oldname\" (it's neither a file nor a directory).");		}	}	// MY_DIR_COPY	function my_dir_copy($oldname, $newname, $follow_symlinks=true)	{		$this->my_mkdir($newname);		$dir = $this->my_opendir($oldname);		while($file = readdir($dir)){			if($file == "." || $file == ".."){				continue;			}			if($this->my_dir_exists($oldname.$this->conf['slash'].$file)				&& $this->my_dir_exists($newname.$this->conf['slash'].$file)) {				$this->my_dir_copy($oldname.$this->conf['slash'].$file, $newname.$this->conf['slash'].$file, $follow_symlinks);			}			else $this->my_copy($oldname.$this->conf['slash'].$file, $newname.$this->conf['slash'].$file, $follow_symlinks);		}		closedir($dir);	}	// MY_IS_WRITABLE	function my_is_writable($file)	{		if(!$this->my_file_exists($file)){			return true;		}		$fp = $this->run_silently("fopen", $file, "w");		if($fp == false){			return false;		}		else{			fclose($fp);			return true;		}	}	// MY_SYMLINK	function my_symlink($from, $to)	{		$this->my_unlink($to);		$this->logger->log ("Symlinking $to -> $from");		return $this->run_silently("symlink", $from, $to);	}	// MY_DELETE	function my_delete($file) /* recursive deletion of directories and files */	{		if($this->my_file_exists($file) || $this->my_link_exists($file)){			$this->logger->log ("Deleting: $file");			$this->my_unlink($file);		}		else if($this->my_dir_exists($file)){			$this->logger->log ("Removing directory: $file");			$this->run_command("rm -rf $file");		}	}	// MY_MKDIR_SILENTLY	function my_mkdir_silently($dir)	{		return $this->my_mkdir_long($dir, true);	}	// MY_MKDIR_LONG	function my_mkdir_long($dir, $silent = false)	{		if(!$this->my_dir_exists($dir)){			if ($this->is_broken_link ($dir)) {				$this->my_unlink ($dir);			}			$this->run_command("mkdir -p '$dir'", "Cannot create directory: $dir");		}		return true;	}	// MY_MKDIR	function my_mkdir($dir, $silent = false)	{		if(!$this->my_dir_exists($dir)){			$this->logger->log ("Creating directory: $dir");			if(!$this->run_silently("mkdir", $dir)){				if(!$silent){				  $this->on_error ("Cannot create directory: $dir");				}				return false;			}		}		return true;	}	// IS_BROKEN_LINK	function is_broken_link($file)	{		return ($this->strip_symlink($file) == "");	}	// MY_LIST_DIR	function my_list_dir($path, $pattern)	{		if(function_exists('glob')) {			return glob($this->make_path($path, $pattern));		}		$files_list = array();		$dir = $this->my_opendir($path);		while($file = readdir($dir)){			if($file == "." || $file == ".."){				continue;			}			if($this->my_fnmatch($pattern, $file)){				array_push($files_list, $this->nice_path("$path/$file"));			}		}		closedir($dir);		return $files_list;	}	// MY_BACKUP	function my_backup($file, $backup_link_dest=false)	{		if($this->my_link_exists($file)){ /* don't backup links */			if($backup_link_dest){				$dest = $this->strip_symlink($file);				if(empty($dest)){					$this->my_unlink($file);				}				else{					$this->logger->log ("Backing-up link destination: $dest");					$this->my_copy($dest, $dest.$this->conf['backup_suffix']);					$new_file = $dest.$this->conf['backup_suffix'];				}			}			else{				$this->logger->log ("Not backing-up a link: $file");			}		}		elseif($this->my_file_exists($file)){			$this->logger->log ("Backing-up file: $file");			$this->my_copy($file, $file.$this->conf['backup_suffix']);			$new_file = $file.$this->conf['backup_suffix'];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -