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

📄 ad_skin_import.php

📁 泛微协同办公系统标准版E-office V5.5的源代码内含泛微办公系统V5.5自动注册文件。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php

class ad_langs
{

	var $base_url;

	function ad_langs( )
	{
		global $IN;
		global $INFO;
		global $DB;
		global $SKIN;
		global $ADMIN;
		global $std;
		global $MEMBER;
		global $GROUP;
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		foreach ( $tmp_in as $k => $v )
		{
		}
		switch ( $IN['code'] )
		{
		case "doimport" :
			$this->doimport( );
			break;
		case "import" :
			$this->import( );
			break;
		case "remove" :
			$this->remove( );
			break;
		default :
			$this->list_current( );
			break;
		}
	}

	function remove( )
	{
		global $IN;
		global $INFO;
		global $DB;
		global $SKIN;
		global $ADMIN;
		global $std;
		global $MEMBER;
		global $GROUP;
		if ( $IN['id'] == "" )
		{
			$ADMIN->error( "没有选择需要导入的 tar 文件!" );
		}
		$this->tar_with_path = $INFO['base_dir']."archive_in/".$IN['id'];
		if ( !unlink( $this->tar_with_path ) )
		{
			$ADMIN->error( "无法删除这个文件,请检查文件属性。" );
		}
		$std->boink_it( $ADMIN->base_url."act=import" );
		exit( );
	}

	function import( )
	{
		global $IN;
		global $INFO;
		global $DB;
		global $SKIN;
		global $ADMIN;
		global $std;
		global $MEMBER;
		global $GROUP;
		if ( $IN['id'] == "" )
		{
			$ADMIN->error( "没有选择需要导入的 tar 文件!" );
		}
		$this->tar_with_path = $INFO['base_dir']."archive_in/".$IN['id'];
		$this->work_path = $INFO['base_dir']."archive_in";
		if ( !file_exists( $this->tar_with_path ) )
		{
			$ADMIN->error( "无法找到文件,可能其他管理员删除了此文件。" );
		}
		$this->tar_file = $IN['id'];
		$this->name_translated = preg_replace( "/^(css|image|set|wrap|tmpl)-(.+?)\\.(\\S+)\$/", "\\2", $this->tar_file );
		$this->name_translated = preg_replace( "/_/", " ", $this->name_translated );
		require( ROOT_PATH."sources/lib/tar.php" );
		$this->tar = new tar( );
		switch ( $IN['type'] )
		{
		case "css" :
			$this->css_import( );
			break;
		case "wrap" :
			$this->wrap_import( );
			break;
		case "image" :
			$this->image_import( );
			break;
		case "tmpl" :
			$this->template_import( );
			break;
		case "set" :
			$this->set_import( );
			break;
		default :
			$ADMIN->error( "无法认证的文件格式" );
			break;
		}
	}

	function set_import( )
	{
		global $IN;
		global $INFO;
		global $DB;
		global $SKIN;
		global $ADMIN;
		global $std;
		global $MEMBER;
		global $GROUP;
		$images_dir = $INFO['base_dir']."style_images";
		$skins_dir = $INFO['base_dir']."Skin";
		if ( !is_writeable( $images_dir ) )
		{
			$ADMIN->error( "无法写入 {$images_dir} ,请检查你的目录属性设置。" );
		}
		if ( !is_dir( $skins_dir ) )
		{
			$ADMIN->error( "无法写入 {$skins_dir} ,请检查你的目录属性设置。" );
		}
		if ( !is_writeable( $skins_dir ) )
		{
			$ADMIN->error( "无法写入 {$skins_dir} ,请检查你的目录属性设置。" );
		}
		$this->tar->new_tar( $this->work_path, $this->tar_file );
		$files = $this->tar->list_files( );
		if ( !$this->check_archive( $files ) )
		{
			$ADMIN->error( "此文件不是有效的 tar 文件,请重新上传文件。" );
		}
		$DB->query( "SELECT COUNT(*) as count FROM ibf_tmpl_names" );
		$tmpl_count = $DB->fetch_row( );
		$new_dir = preg_replace( "/^(.+?)\\.tar\$/", "\\1", $this->tar_file );
		$this->new_dir = $new_dir;
		if ( !mkdir( $this->work_path."/".$new_dir, 511 ) )
		{
			$ADMIN->error( "目录建立失败,无法导入主题界面。请检查目录属性 'archive_in'" );
		}
		@chmod( $this->work_path."/".$new_dir, 511 );
		$next_id = array( "css" => 0, "wrap" => 0, "templates" => 0, "macro" => 0 );
		$DB->query( "INSERT INTO ibf_tmpl_names SET skname=\"".$this->name_translated." (Set Import).{$tmpl_count['count']}\"" );
		$next_id['templates'] = $DB->get_insert_id( );
		$DB->query( "INSERT INTO ibf_css SET css_name=\"".$this->name_translated." (Set Import)\"" );
		$next_id['css'] = $DB->get_insert_id( );
		$DB->query( "INSERT INTO ibf_templates SET name=\"".$this->name_translated." (Set Import)\"" );
		$next_id['wrap'] = $DB->get_insert_id( );
		$DB->query( "SELECT MAX(set_id) as max FROM ibf_macro_name" );
		$max = $DB->fetch_row( );
		$next_id['macro'] = $max['max'] + 1;
		$next_id['images'] = str_replace( " ", "_", substr( $this->name_translated, 0, 8 ) )."-".substr( time( ), 7, 10 );
		if ( !mkdir( $images_dir."/".$next_id['images'], 511 ) )
		{
			$this->import_error( "无法建立新目录 style_images", $next_id );
		}
		@chmod( $images_dir."/".$next_id['images'], 511 );
		if ( !mkdir( $skins_dir."/s".$next_id['templates'], 511 ) )
		{
			$this->import_error( "无法在主题目录中建立新目录", $next_id );
		}
		@chmod( $skins_dir."/s".$next_id['templates'], 511 );
		$this->tar->extract_files( $this->work_path."/".$new_dir );
		if ( $this->tar->error != "" )
		{
			$this->import_error( $this->tar->error, $next_id );
		}
		if ( file_exists( $this->work_path."/".$new_dir."/templates_conf.inc" ) )
		{
			require( $this->work_path."/".$new_dir."/templates_conf.inc" );
			$template_config = array(
				"author" => stripslashes( $config['author'] ),
				"email" => stripslashes( $config['email'] ),
				"url" => stripslashes( $config['url'] )
			);
			$db_string = $DB->compile_db_update_string( $template_config );
			$DB->query( "UPDATE ibf_tmpl_names SET {$db_string} WHERE skid='{$next_id['templates']}'" );
		}
		if ( $FH = fopen( $this->work_path."/".$new_dir."/stylesheet.css", "r" ) )
		{
			$css = fread( $FH, filesize( $this->work_path."/".$new_dir."/stylesheet.css" ) );
			fclose( $FH );
			$css = preg_replace( "/\r/", "\n", stripslashes( $css ) );
			$css_string = $DB->compile_db_update_string( array(
				"css_name" => stripslashes( $this->name_translated )." (Import)",
				"css_text" => $css
			) );
			$DB->query( "UPDATE ibf_css SET {$css_string} WHERE cssid='{$next_id['css']}'" );
		}
		else
		{
			$this->import_error( "无法读取上传的CSS文件,请检查后再试", $next_id );
		}
		if ( $FH = fopen( $this->work_path."/".$new_dir."/wrapper.html", "r" ) )
		{
			$text = fread( $FH, filesize( $this->work_path."/".$new_dir."/wrapper.html" ) );
			fclose( $FH );
			$text = preg_replace( "/\r/", "\n", stripslashes( $text ) );
			$wrap_string = $DB->compile_db_update_string( array(
				"name" => stripslashes( $this->name_translated )." (Import)",
				"template" => $text
			) );
			$DB->query( "UPDATE ibf_templates SET {$wrap_string} WHERE tmid='{$next_id['wrap']}'" );
		}
		else
		{
			$this->import_error( "无法读取上传的论坛主题图片文件,请检查后再试", $next_id );
		}
		if ( !$ADMIN->copy_dir( $this->work_path."/".$new_dir."/images", $images_dir."/".$next_id['images'] ) )
		{
			$this->import_error( "无法导入图片,导入停止", $next_id );
		}
		if ( $FH = fopen( $this->work_path."/".$new_dir."/macro.txt", "r" ) )
		{
			$data = fread( $FH, filesize( $this->work_path."/".$new_dir."/macro.txt" ) );
			fclose( $FH );
			$init_array = array( );
			$final_keys = array( );
			$init_array = explode( "\n", $data );
			foreach ( $init_array as $l )
			{
				if ( preg_match( "~=~", $l ) )
				{
					list( $k, $v ) = explode( "~=~", $l );
					$k = trim( $k );
					$v = trim( $v );
					$final_keys[$k] = $v;
				}
			}
			foreach ( $final_keys as $k => $v )
			{
				if ( $v == "*UNASSIGNED*" )
				{
					$v = "";
				}
				$str = $DB->compile_db_insert_string( array(
					"macro_value" => stripslashes( $k ),
					"macro_replace" => stripslashes( $v ),
					"macro_set" => $next_id['macro'],
					"can_remove" => 1
				) );
				$DB->query( "INSERT INTO ibf_macro ({$str['FIELD_NAMES']}) VALUES({$str['FIELD_VALUES']})" );
			}
			$DB->query( "INSERT INTO ibf_macro_name SET set_id='".$next_id['macro']."', set_name='".$this->name_translated."'" );
		}
		else
		{
			$this->import_error( "无法读取你上传的主题文件中 macro.txt 的内容", $next_id );
		}
		$tmpl_string = $DB->compile_db_update_string( $template_config );
		$DB->query( "UPDATE ibf_tmpl_names SET {$tmpl_string} WHERE skid='{$next_id['templates']}'" );
		if ( $FH = fopen( $this->work_path."/".$new_dir."/templates.html", "r" ) )
		{
			$data = fread( $FH, filesize( $this->work_path."/".$new_dir."/templates.html" ) );
			fclose( $FH );
			preg_match_all( "/<!--IBF_GROUP_START:(\\S+?)-->(.+?)<!--IBF_GROUP_END:\\S+?-->/s", $data, $match );
			$i = 0;
			for ( ;	$i < count( $match[0] );	++$i	)
			{
				$match[1][$i] = trim( $match[1][$i] );
				$match[2][$i] = trim( $match[2][$i] );
				$this->process_template_group( $match[2][$i], $next_id['templates'], $match[1][$i], 1 );
			}
		}
		else
		{
			$this->import_error( "无法读取上传的主题文件 templates.html 的内容。", $next_id );
		}
		$DB->query( "SELECT MAX(sid) as new_id FROM ibf_skins" );
		$set = $DB->fetch_row( );
		++$set['new_id'];
		$new_name = stripslashes( $this->name_translated )." (Import)".$set['new_id'];
		$skin_string = $DB->compile_db_insert_string( array(
			"sname" => $new_name,
			"sid" => $set['new_id'],
			"set_id" => $next_id['templates'],
			"tmpl_id" => $next_id['wrap'],
			"img_dir" => $next_id['images'],
			"css_id" => $next_id['css'],
			"macro_id" => $next_id['macro'],
			"hidden" => 0,
			"default_set" => 0
		) );
		$DB->query( "INSERT INTO ibf_skins (".$skin_string['FIELD_NAMES'].") VALUES(".$skin_string['FIELD_VALUES'].")" );
		$ADMIN->rm_dir( $this->work_path."/".$new_dir );
		$ADMIN->done_screen( "主题界面导入", "主题界面管理", "act=sets" );
	}

	function process_template_group( $raw, $setid, $group, $isnew = 0 )
	{
		global $IN;
		global $INFO;
		global $DB;
		global $SKIN;
		global $ADMIN;
		global $std;
		global $MEMBER;
		global $GROUP;
		$root_path = $INFO['base_dir'];
		$skin_dir = $root_path."Skin/s".$setid;
		if ( $INFO['safe_mode_skins'] != 1 )
		{
			if ( SAFE_MODE_ON == 1 )
			{
				if ( $isnew == 1 )
				{
					$DB->query( "DELETE FROM ibf_tmpl_names WHERE skid='{$setid}'" );
				}
				$ADMIN->error( "侦测到论坛安全模式功能,你需要修改启用论坛设置[安全模式主题],你可以在[论坛变量设置]里进行设置。" );
			}
			if ( $isnew == 1 )
			{
				if ( !is_writeable( $root_path."Skin" ) )
				{
					$DB->query( "DELETE FROM ibf_tmpl_names WHERE skid='{$setid}'" );
					$ADMIN->error( "无法写入目录 'Skin',请检查目录属性(CHMOD 777)。" );
				}
			}
			else if ( !is_writeable( $skin_dir ) )
			{
				$ADMIN->error( "无法写入目录 '{$skin_dir}',请检查目录属性(CHMOD 777)。" );
			}
		}

⌨️ 快捷键说明

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