compiler.inc

来自「eGroupWare is a multi-user, web-based gr」· INC 代码 · 共 667 行 · 第 1/2 页

INC
667
字号
		}		$dir = $GLOBALS['WWW_ROOT_DISK'].'theme/'.$GLOBALS['__COMPILER__']['tname'].'/';		$dst = $fc['dst'];	} else {		$dir = $GLOBALS['INCLUDE'].'theme/'.$GLOBALS['__COMPILER__']['tname'].'/';		if ($fc['dst'][0] == '!' || $fc['dst'][0] == '@') {			$dst = substr($fc['dst'],1);		} else {			$dst = $fc['dst'];		}	}	$cmp =& $GLOBALS['__COMPILER__'];	$file_data = str_replace($GLOBALS['CMP_LOC_S'], $GLOBALS['CMP_LOC_K'], $file_data);	if (!$dst) {		return;	}	if ($dst[0] == '#') {		$dst = substr($dst, 1);		$dir = $GLOBALS['WWW_ROOT_DISK'];	}	if (!($fp = fopen($dir.$dst, 'wb'))) {		exit('Couldn\'t write to '. $dir . $dst);	}	fwrite($fp, $file_data);	fclose($fp);}function parse_msgs($file){	$data = file($file);	foreach ($data as $k => $v) {		$m = trim(strtok($v, "\t"), ':');		if (isset($GLOBALS['MSG'][$m])) {			if ($GLOBALS['MSG'][$m]['file'] != $file) {				continue;			}			exit('duplicated message: '.$m.' in '.$file.' on line #'.($k + 1).', previous entry found on line #'.$GLOBALS['MSG'][$m]['line'].' in '.$GLOBALS['MSG'][$m]['file']);		}		$GLOBALS['MSG'][$m] = array('data' => resolve_sections(trim(strtok("\t"))), 'file' => $file, 'line'=> $k);	}}function build_msg($file){	if (isset($GLOBALS['MSG_FILES'][$file])) {		return;	}	$GLOBALS['MSG_FILES'][$file] = 1;	/*	 * we 1st read in the default msg file for the equivalent translation and read it in	 * then we replace simular values from the actual msg file. This allows partial msg	 * files to be used inside themes	 */	$ts = substr(strstr(dirname($file), '/'), 1);	$ts = $GLOBALS['DATA_DIR'] . 'thm/default/i18n/' . $ts . '/msg';	$GLOBALS['CURFILE'] = '';	if (file_exists($file)) {		if (preg_match('!thm/([^/]+)/i18n!', $file, $m)) {			parse_sections(@file_get_contents($GLOBALS['DATA_DIR'] . 'thm/'.$m[1].'/tmpl/messages'), '', 1);		}		parse_msgs($file);	}	if ($ts != $file && file_exists($ts)) {		parse_sections(file_get_contents($GLOBALS['DATA_DIR'] . 'thm/default/tmpl/messages'), '', 1);		parse_msgs($ts);	}}function resolve_inc_refs($file){	$curf =& $GLOBALS['file_cache'][$file];	if (isset($curf['resolved'])) {		return;	}	if (!isset($curf['include'])) {		$curf['resolved'] = 1;		$curf['include'] = array();		return;	}	$ar =& $curf['include'];	$vs = array_keys($ar);	foreach($vs as $v) {		if ($v == $file) {			continue;		}		resolve_inc_refs($v);		$ar = array_merge($ar, $GLOBALS['file_cache'][$v]['include']);	}	$ar[$file] = $file;	$curf['resolved'] = 1;}function resolve_compile($file){	if (isset($GLOBALS['file_cache'][$file])) {		return;	}	resolve_refs($file, $file);	resolve_inc_refs($file);	if (!empty($GLOBALS['file_cache'][$file]['src'])) {		$GLOBALS['file_cache'][$file]['compiled'] = compile_file($GLOBALS['file_cache'][$file]['src']);	}}function fud_mkdir($dir, $perms=0700){	if (!@is_dir($dir) && !@mkdir($dir, $perms)) {		exit('unable to make directory (<b>'.$dir.'</b>)<br>');	}}function compile_all($tset='default', $lang='english', $tname='default'){	$oldmask = umask(0133);	/* make sure we can use the specified values to make 'nice' directory names */	$tname = preg_replace('![^A-Za-z0-9-]!', '_', $tname);	$tset = preg_replace('![^A-Za-z0-9-]!', '_', $tset);	$lang = preg_replace('![^A-Za-z0-9-]!', '_', $lang);	$GLOBALS['__COMPILER__'] 	= array();	$GLOBALS['MSG']                 = array();	$GLOBALS['MSG_FILES']           = array();	$GLOBALS['TC']                  = array();	$GLOBALS['file_cache']          = array();	copy($GLOBALS['DATA_DIR'].'sql/'.__dbtype__.'_db.inc', $GLOBALS['DATA_DIR'].'src/db.inc.t');	$GLOBALS['__COMPILER__'] = array('tset' => $tset, 'lang' => $lang, 'tname' => $tname);	$cmpl =& $GLOBALS['__COMPILER__'];	if (substr($GLOBALS['WWW_ROOT'], -1) != '/') {		$cmpl['ROOT'] = $GLOBALS['WWW_ROOT'] . '/index.php';		$cmpl['THEME_ROOT'] = $GLOBALS['WWW_ROOT'] . '/theme/' . $tname;	} else {		$cmpl['ROOT'] = $GLOBALS['WWW_ROOT'] . 'index.php';		$cmpl['THEME_ROOT'] = $GLOBALS['WWW_ROOT'] . 'theme/' . $tname;	}	$cmpl['THEME_ROOT_DISK'] = $GLOBALS['WWW_ROOT_DISK'].'theme/'.$tname;	$cmpl['THEME_IMAGE_ROOT'] = $cmpl['THEME_ROOT'].'/images';	$file1 = $GLOBALS['DATA_DIR'].'thm/'.$tset.'i18n/'.$lang.'/charset';	$file2 = $GLOBALS['DATA_DIR'].'thm/default/i18n/'.$lang.'/charset';	$u = umask(0);	$perms = $GLOBALS['FUD_OPT_2'] & 8388608 ? 0700 : 0777;	if (strncmp(PHP_SAPI, 'apache', 6) && $perms == 0700) {		$perms = 0711;	}	fud_mkdir($GLOBALS['WWW_ROOT_DISK'].'theme', $perms);	fud_mkdir($GLOBALS['WWW_ROOT_DISK'] . 'theme/' . $tname, $perms);	fud_mkdir($GLOBALS['DATA_DIR'] . 'include/theme', $perms);	fud_mkdir($GLOBALS['DATA_DIR'] . 'include/theme/' . $tname, $perms);	umask($u);	$GLOBALS['CMP_LOC_S'] = array('{ROOT}', '{THEME_ROOT}', '{THEME_ROOT_DISK}', ".'';", ".''.");	$GLOBALS['CMP_LOC_K'] = array($cmpl['ROOT'], $cmpl['THEME_ROOT'], $cmpl['THEME_ROOT_DISK'], ';', '.');	$charset = @is_file($file1) ? $file1 : $file2;	$GLOBALS['char_set'] = trim(file_get_contents($charset));	$prim_msg_file = $GLOBALS['DATA_DIR'].'thm/'.$cmpl['tset'].'/i18n/'.$cmpl['lang'].'/msg';	$back_msg_file = $GLOBALS['DATA_DIR'].'thm/default/i18n/'.$cmpl['lang'].'/msg';	/*	 * build the message array	 */	if (@file_exists($prim_msg_file)) {		build_msg($prim_msg_file);	}	/*	 * append any missing entries from the default language file	 */	build_msg($back_msg_file);	$dir = opendir($GLOBALS['DATA_DIR'].'/thm/default/tmpl');	while ($file = readdir($dir)) {		if ($file == '.' || $file == '..') continue;		if (substr($file, -5) != '.tmpl') {			continue;		}		resolve_compile($file);		if (isset($GLOBALS['file_cache'][$file]['inline'])) {			continue;		}		generate_file($file);		if (isset($GLOBALS['PHP_FILE_SEC'])) {			foreach($GLOBALS['PHP_FILE_SEC'] as $k => $v) {				foreach($v as $k2 => $v2) {					unset($GLOBALS['TC'][$k][$k2]);				}			}			unset($GLOBALS['PHP_FILE_SEC']);		}		unset($GLOBALS['INCLUDE_LIST']);	}	closedir($dir);	@umask($oldmask);	$thm = new cmpl_local_theme;	$thm->name = $tname;	$thm->theme = $tset;	$thm->lang = $lang;	copyimages($thm);	copyhelp($thm);}class cmpl_local_theme{	var $name;	var $theme;	var $lang;}function fudcopy($src, $dest, $mask='!.*!i', $recur=false){	$src = preg_replace('!/*$!', '', $src);	$dest = preg_replace('!/*$!', '', $dest);	$perms = $GLOBALS['FUD_OPT_2'] & 8388608 ? 0600 : 0666;	if (strncmp(PHP_SAPI, 'apache', 6) && $perms == 0600) {		$perms = 0644;	}	if (!($dp = opendir($src))) {		echo 'Cannot open directory "'.$src.'"<br>';		return;	}	while ($de = readdir($dp)) {		if ($de == '.' || $de == '..') continue;		if (!preg_match($mask, $de, $regs)) {			continue;		}		$path = $src . '/' . $de;		$nd = $dest . '/' . $de;		if (@is_dir($path) && $recur == true) {			if (!@is_dir($nd) && !@mkdir($nd, 0777)) {				exit('can\'t mkdir ('.$nd.')<br>');			}			fudcopy($path, $nd, $mask, true);		} else {			if (!@copy($path, $nd) && !@file_exists($nd)) {				echo 'cannot copy "'.$path.'" to "'.$nd.'"<br>';			} else {				@chmod($nd, $perms);			}		}	}	closedir($dp);}function copyimages($thm){	$path = $GLOBALS['WWW_ROOT_DISK'].'theme/'.$thm->name.'/images';	$u = umask(0);	if (!@is_dir($path) && !@mkdir($path, 0777)) {		exit('Failed Creating: '.$path.'<br>');	}	fudcopy($GLOBALS['DATA_DIR'].'thm/default/images', $path, '!\.(gif|jpeg|png|jpg)$!i');	fudcopy($GLOBALS['DATA_DIR'].'thm/default/i18n/'.$thm->lang.'/img', $path, '!\.(gif|jpeg|png|jpg)$!i');	if ($thm->theme != 'default') {		if (@file_exists($GLOBALS['DATA_DIR'].'thm/'.$thm->theme.'/images')) {			fudcopy($GLOBALS['DATA_DIR'].'thm/'.$thm->theme.'/images', $path, '!\.(gif|jpeg|png|jpg)$!i');		}		if (@file_exists($GLOBALS['DATA_DIR'].'thm/'.$thm->theme.'/i18n/'.$thm->lang.'/img')) {			fudcopy($GLOBALS['DATA_DIR'].'thm/'.$thm->theme.'/i18n/'.$thm->lang.'/img', $path, '!\.(gif|jpeg|png|jpg)$!i');		}	}	umask($u);}function copyhelp($thm){	$path = $GLOBALS['WWW_ROOT_DISK'].'theme/'.$thm->name.'/help';	$src = $GLOBALS['DATA_DIR'].'thm/'.$thm->theme.'/i18n/'.$thm->lang.'/help';	if (!@file_exists($src)) {		$src = $GLOBALS['DATA_DIR'].'thm/default/i18n/'.$thm->lang.'/help';		if (!@file_exists($src)) {			$src = $GLOBALS['DATA_DIR'].'thm/default/i18n/english/help';		}	}	$rp =& $GLOBALS['__COMPILER__']['ROOT'];	$u = umask(0);	$perms = $GLOBALS['FUD_OPT_2'] & 8388608 ? 0600 : 0666;	if (strncmp(PHP_SAPI, 'apache', 6) && $perms == 0600) {		$perms = 0644;	}	if (!@is_dir($path) && !@mkdir($path, 0777)) {		exit('Failed Creating: '.$path.'<br>');	}	$path .= '/';	$dp = opendir($src);	$src .= '/';	while ($de = readdir($dp)) {		if ($de == '.' || $de == '..') continue;		if (!@is_file($src . $de) || substr($de, -4) != '.hlp') {			continue;		}		if (!($fp = fopen($path . $de, 'wb'))) {			exit('Failed to write to: '.$path . '/' . $de.'<br>');		}		fwrite($fp, str_replace('{ROOT}', $rp, file_get_contents($src . $de)));		fclose($fp);		@chmod($src . $de, $perms);	}	closedir($dp);	umask($u);}?>

⌨️ 快捷键说明

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