Beispiel #1
0
 function SaveAvatar()
 {
     $Images = new ImagesHandler('Filedata');
     $IoHandler = new IoHandler();
     $path = $this->QueryString('image_path');
     $item = $this->QueryString('item');
     $item = $this->QueryString('item_id');
     if (!$item || $item == '') {
         $item = 'user';
     }
     $Images->item_type = $item;
     $imgId = $this->ImgLogic->AddNewImage();
     $rpath = 'images/' . $item . '/' . face_path($imgId);
     if (!file_exists($path)) {
         $result['status'] = "failed";
         $result['message'] = urlencode('头像裁剪失败,图片传输过程中丢失');
         echo json_encode($result);
         exit;
     }
     if (!file_exists($rpath)) {
         $IoHandler->MakeDir($rpath);
     }
     $prefix = $rpath . $imgId;
     $ret = $Images->thumb($path, false, 1, $prefix);
     if ($ret && count($ret) == 2) {
         //$thumbname01=$prefix."_p.".$type;
         if ($item == 'user') {
             $thumbname02 = $ret['small'];
             $_SESSION['face_url'] = $thumbname02;
             $_SESSION['face_url_p'] = $ret['big'];
             $userdata = array();
             $userdata['face_url'] = $thumbname02;
             $ret = $this->UserLogic->UpdateUser2($userdata, $this->User['uid']);
         }
         //delete the uploaded temp file
         $IoHandler->DeleteFile($path);
         $result['status'] = "ok";
         $result['image'] = $ret;
         echo json_encode($result);
     } else {
         $result['status'] = "failed";
         $result['message'] = urlencode($Images->errMsg);
         echo urldecode(json_encode($result));
     }
 }
Beispiel #2
0
function ajherrorlog($type='',$log='',$halt=1) {
	$logfile = ROOT_PATH . 'errorlog/'.$type . '-' . date('Y-m').'.php';
	if (!is_file($logfile)) {
		$log ="<? exit; ?>\r\n" . $log;
	}
	$log = "[".my_date_format(time(),"Y-m-d H:i:s")."]" . $log . "\r\n";

	global $IoHandler;
	if(is_null($IoHandler)) {
		$load = new Load();
		$load->lib('io');
		$IoHandler = new IoHandler();
		$log = " \r\n ------------------------------------------------------ \r\n " . $log;
	}
	if (!is_dir(dirname($logfile))) {
		$IoHandler->MakeDir(dirname($logfile));
	}

	$IoHandler->WriteFile($logfile,$log,'a');

	if($halt) {
		exit();
	}
}
Beispiel #3
0
 private function SaveAvatar($tep_image_path, $item, $item_id)
 {
     $Images = new ImagesHandler('Filedata');
     $IoHandler = new IoHandler();
     if (!$item || $item == '') {
         $item = 'user';
     }
     $Images->item_type = $item;
     $imgId = $this->ImageLogic->AddNewImage();
     $rpath = 'images/' . $item . '/face/' . face_path($imgId);
     if (!file_exists($tep_image_path)) {
         return false;
     }
     if (!file_exists($rpath)) {
         $IoHandler->MakeDir($rpath);
     }
     $prefix = $rpath . $imgId;
     $ret = $Images->thumb($tep_image_path, false, 1, $prefix);
     if ($ret && count($ret) == 2) {
         $data = array();
         $data['photo'] = $ret['small'];
         $this->ImageLogic->UpdateImage($data, $imgId);
         //delete the uploaded temp file
         $IoHandler->DeleteFile($tep_image_path);
         return $ret;
     } else {
         $IoHandler->DeleteFile($tep_image_path);
         return false;
     }
 }
Beispiel #4
0
 function initPath($path)
 {
     $ret = $path;
     $path = substr($path, -1) == '/' ? $path : dirname($path);
     if (!is_dir($path)) {
         IoHandler::MakeDir($path);
     }
     return $ret;
 }
Beispiel #5
0
	function DoExport()
	{
		$this->CheckAdminPrivs('dbexport');
		global $sizelimit, $startrow, $extendins, $sqlcompat, $sqlcharset, $dumpcharset, $usehex, $complete, $excepttables;
		extract($this->Post);extract($this->Get);

		$excepttables=array(TABLE_PREFIX."sessions",);

		$time=$timestamp=time();
		$tablepre=TABLE_PREFIX;

		$this->DatabaseHandler->Query('SET SQL_QUOTE_SHOW_CREATE=1', 'SKIP_ERROR');
		if(!$filename || preg_match("/(\.)(exe|jsp|asp|aspx|cgi|fcgi|pl)(\.|$)/i", $filename))
		{
			$this->Messager("备份文件名无效");
		}

				if($type == 'all_tables') {
			$tables = $this->_array_keys2($this->_fetch_table_list($tablepre), 'Name');
		}
		elseif($type == 'custom')
		{
			$tables = array();
			if(empty($setup))
			{
				$tables=cache("tables",-1,true);
			}
			else
			{
				cache('tables',-1);
				cache($customtables);
				$tables = & $customtables;
			}
			if( !is_array($tables) || empty($tables))
			{
				$this->Messager("没有要导出的数据表");
			}
		}


		$volume = intval($volume) + 1;
		$idstring = '# Identify: '.base64_encode("$timestamp,".SYS_VERSION.",$type,$method,$volume")."\n";


		$dumpcharset = $sqlcharset ? $sqlcharset : str_replace('-', '', $this->Config['charset']);
		$setnames = ($sqlcharset && $this->DatabaseHandler->GetVersion() > '4.1' && (!$sqlcompat || $sqlcompat == 'MYSQL41')) ? "SET NAMES '$dumpcharset';\n\n" : '';
		if($this->DatabaseHandler->GetVersion() > '4.1') {
			if($sqlcharset) {
				$this->DatabaseHandler->Query("SET NAMES '".$sqlcharset."';\n\n");
			}
			if($sqlcompat == 'MYSQL40') {
				$this->DatabaseHandler->Query("SET SQL_MODE='MYSQL40'");
			} elseif($sqlcompat == 'MYSQL41') {
				$this->DatabaseHandler->Query("SET SQL_MODE=''");
			}
		}

		
		$backupdir = 'db/' . ($f = str_replace(array('/', '\\', '.'), '', $filename));
		$backupfilename = './backup/'.$backupdir.'/'.$f;
		if (!is_dir(($d = dirname($backupfilename)))) {
			$load = new Load();
			$load->lib('io');
			$IoHandler = new IoHandler();
			$IoHandler->MakeDir($d);
		}
		

		if($usezip) {
			require_once FUNCTION_PATH.'zip.func.php';
		}

		if($method == 'multivol') {
			$sqldump = '';
			$tableid = intval($tableid);
			$startfrom = intval($startfrom);
			
			$complete = TRUE;

			for(; $complete && $tableid < count($tables) && strlen($sqldump) + 500 < $sizelimit * 1000; $tableid++) {
				$sqldump .= $this->_sql_dump_table($tables[$tableid], $startfrom, strlen($sqldump));
				if($complete) {
					$startfrom = 0;
				}
			}
			
			$dumpfile = $backupfilename."-%s".'.sql';
			!$complete && $tableid--;
			if(trim($sqldump)) {
				$sqldump = "$idstring".
				"# <?exit();?>\n".
				"# TTTuangou Multi-Volume Data Dump Vol.$volume\n".
				"# Version: TTTuangou ".SYS_VERSION."\n".
				"# Time: $time\n".
				"# Type: $type\n".
				"# Table Prefix: $tablepre\n".
				"#\n".
				"# TTTuangou Home: http:\/\/www.tttuangou.net\n".
				"# Please visit our website for newest infomation about TTTuangou\n".
				"# --------------------------------------------------------\n\n\n".
				"$setnames".
				$sqldump;
				$dumpfilename = sprintf($dumpfile, $volume);
				@$fp = fopen($dumpfilename, 'wb');
				@flock($fp, 2);
				if(@!fwrite($fp, $sqldump)) {
					@fclose($fp);
					$this->Messager("备份文件名有问题");
				} else {
					fclose($fp);
					if($usezip == 2) {
						$fp = fopen($dumpfilename, "r");
						$content = @fread($fp, filesize($dumpfilename));
						fclose($fp);
						$zip = new zipfile();
						$zip->addFile($content, basename($dumpfilename));
						$fp = fopen(sprintf($backupfilename."-%s".'.zip', $volume), 'w');
						if(@fwrite($fp, $zip->file()) !== FALSE) {
							@unlink($dumpfilename);
						}
						fclose($fp);
					}
					unset($sqldump, $zip, $content);
					$this->Messager("分卷备份: 数据文件 #{$volume} 成功创建,程序将自动继续。
", "admin.php?mod=db&code=doexport&type=".rawurlencode($type)."&saveto=server&filename=".rawurlencode($filename)."&method=multivol&sizelimit=".rawurlencode($sizelimit)."&volume=".rawurlencode($volume)."&tableid=".rawurlencode($tableid)."&startfrom=".rawurlencode($startrow)."&extendins=".rawurlencode($extendins)."&sqlcharset=".rawurlencode($sqlcharset)."&sqlcompat=".rawurlencode($sqlcompat)."&exportsubmit=yes&usehex=$usehex&usezip=$usezip");

				}
			} else {
				$volume--;
				$filelist = '<ul>';

				if($usezip == 1) {
					$zip = new zipfile();
					$zipfilename = $backupfilename.'.zip';
					$unlinks = '';
					for($i = 1; $i <= $volume; $i++) {
						$filename = sprintf($dumpfile, $i);
						$fp = fopen($filename, "r");
						$content = @fread($fp, filesize($filename));
						fclose($fp);
						$zip->addFile($content, basename($filename));
						$unlinks .= "@unlink('$filename');";
						$filelist .= "<li><a href=\"$filename\">$filename\n";
					}
					$fp = fopen($zipfilename, 'w');
					if(@fwrite($fp, $zip->file()) !== FALSE) {
						eval($unlinks);
					} else {
						$this->Messager('database_export_multivol_succeed');
					}
					unset($sqldump, $zip, $content);
					fclose($fp);
					@touch('./backup/'.$backupdir.'/index.htm');
					$filename = $zipfilename;
					$this->Messager("数据成功备份并压缩至服务器 <a href=\"$filename\">$filename</a> 中。",null);
				} else {
					@touch('./backup/'.$backupdir.'/index.htm');
					for($i = 1; $i <= $volume; $i++) {
						$filename = sprintf($usezip == 2 ? $backupfilename."-%s".'.zip' : $dumpfile, $i);
						$filelist .= "<li><a href=\"$filename\">$filename\n";
					}
					$this->Messager("恭喜您,全部 $volume 个备份文件成功创建,备份完成。
".$filelist ,null);
				}
			}

		} else {

			$tablesstr = '';
			foreach($tables as $table) {
				$tablesstr .= '"'.$table.'" ';
			}

			require './config.inc.php';
			list($dbhost, $dbport) = explode(':', $dbhost);

			$query = $this->DatabaseHandler->Query("SHOW VARIABLES LIKE 'basedir'");
			list(, $mysql_base) = $db->fetch_array($query, MYSQL_NUM);

			$dumpfile = addslashes(dirname(dirname(__FILE__))).'/'.$backupfilename.'.sql';
			@unlink($dumpfile);

			$mysqlbin = $mysql_base == '/' ? '' : addslashes($mysql_base).'bin/';
			@shell_exec($mysqlbin.'mysqldump --force --quick '.($this->DatabaseHandler->GetVersion() > '4.1' ? '--skip-opt --create-options' : '-all').' --add-drop-table'.($extendins == 1 ? ' --extended-insert' : '').''.($this->DatabaseHandler->GetVersion() > '4.1' && $sqlcompat == 'MYSQL40' ? ' --compatible=mysql40' : '').' --host="'.$dbhost.($dbport ? (is_numeric($dbport) ? ' --port='.$dbport : ' --socket="'.$dbport.'"') : '').'" --user="******" --password="******" "'.$dbname.'" '.$tablesstr.' > '.$dumpfile);

			if(@is_file($dumpfile)) {

				if($usezip) {
					require_once FUNCTION_PATH.'zip.func.php';
					$zip = new zipfile();
					$zipfilename = $backupfilename.'.zip';
					$fp = fopen($dumpfile, "r");
					$content = @fread($fp, filesize($dumpfile));
					fclose($fp);
					$zip->addFile($idstring."# <?exit();?>\n ".$setnames."\n #".$content, basename($dumpfile));
					$fp = fopen($zipfilename, 'w');
					@fwrite($fp, $zip->file());
					fclose($fp);
					@unlink($dumpfile);
					@touch('./backup/'.$backupdir.'/index.htm');
					$filename = $backupfilename.'.zip';
					unset($sqldump, $zip, $content);
					$this->Messager('database_export_zip_succeed');
				} else {
					if(@is_writeable($dumpfile)) {
						$fp = fopen($dumpfile, 'rb+');
						@fwrite($fp, $idstring."# <?exit();?>\n ".$setnames."\n #");
						fclose($fp);
					}
					@touch('./backup/'.$backupdir.'/index.htm');
					$filename = $backupfilename.'.sql';
					$this->Messager('database_export_succeed');
				}

			} else {

				$this->Messager('database_shell_fail');

			}

		}
	}
Beispiel #6
0
function upload_image($image_path = '',$filed='face',$small_width=80,$small_height=80)
{
	if($image_path == '') {
		$image_path = IMAGE_PATH.'/'.$filed.'/';
	}
	$date=date("Y-m-d");
	if(empty($_FILES) or empty($filed))	{
		return array('error'=>__('上传图片出错!请检查您的服务器环境!'));
	}
	if ($_FILES[$filed]['name']=='') {
		return array('error'=>__('您没有选择需要上传的图片!'));
	}
	$default_type=array('jpg','pic','png','jpeg','bmp','gif');	$imgary=explode('.',$_FILES[$filed]['name']);
	if(!in_array(strtolower($imgary[count($imgary)-1]),$default_type)){
		return array('error'=>'不支持的图片格式 ['.$imgary[count($imgary)-1].'] !');
	}

	require_once LIB_PATH . 'upload.han.php';
	$upload_handler = new UploadHandler($_FILES, $image_path, $filed , true);

	if(is_dir($image_path.$date)==false or is_dir($image_path.SMALL_PIC_PREFIX.$date)==false)
	{
		require_once LIB_PATH. 'io.han.php';
		IoHandler::MakeDir($image_path.$date);
		IoHandler::MakeDir($image_path.SMALL_PIC_PREFIX.$date);
	}

	$upload_handler->setMaxSize(1024);	$name = $date.'/'.substr(md5(microtime()).'.'.strtolower(end(explode('.', $_FILES[$filed]['name']))),-15);

	$size = $_FILES[$field]['size'];

	$photo['name']=$name;
	$photo['size']=$size;

	$upload_handler->setNewName($name);

	$result = $upload_handler->doUpload();

		if (false == $result)
	{
		return array('error'=>$upload_handler->getError());
	}

	$result = resize_image($image_path.$name,
	$image_path.SMALL_PIC_PREFIX.$name,
	$small_width,
	$small_height,
	false);
	return $name;
}
Beispiel #7
0
	function OpenTable() {
		$this->unicode_table = array();
		if($this->config['SourceLang'] == 'GBK' || $this->config['TargetLang'] == 'GBK') {
			$this->table = CODETABLE_DIR.$this->config['GBtoUnicode_table'];
		} elseif($this->config['SourceLang'] == 'BIG5' || $this->config['TargetLang'] == 'BIG5') {
			$this->table = CODETABLE_DIR.$this->config['BIG5toUnicode_table'];
		}
		$table_cache_file=CACHE_PATH.$this->config['SourceLang'].'-'.$this->config['TargetLang'].".cache.php";
		if(@include($table_cache_file))
		{
			$this->unicode_table=$unicode_table;
			unset($unicode_table);
			return null;
		}
		@$fp = fopen($this->table, 'rb');
		$tabletmp = fread($fp, filesize($this->table));
		for($i = 0; $i < strlen($tabletmp); $i += 4) {
			$tmp = unpack('nkey/nvalue', substr($tabletmp, $i, 4));
			if($this->config['TargetLang'] == 'UTF-8') {
				$this->unicode_table[$tmp['key']] = '0x'.dechex($tmp['value']);
			} elseif($this->config['SourceLang'] == 'UTF-8') {
				$this->unicode_table[$tmp['value']] = '0x'.dechex($tmp['key']);
			} elseif($this->config['TargetLang'] == 'UNICODE') {
				$this->unicode_table[$tmp['key']] = dechex($tmp['value']);
			}
		}
		if(!is_dir(CODETABLE_DIR)) {
			$load = new Load();
			$load->lib('io');
			$IoHandler = new IoHandler();
			$IoHandler->MakeDir(CODETABLE_DIR);
		}
		is_writeable(CODETABLE_DIR) || die("编码缓存目录不可写。请检查:".CODETABLE_DIR);
		if(!is_dir(dirname($table_cache_file))) {
			$load = new Load();
			$load->lib('io');
			$IoHandler = new IoHandler();
			$IoHandler->MakeDir(dirname($table_cache_file));
		}
		@$fp=fopen($table_cache_file,'wb');
		@fwrite($fp,"<?php\r\n\$unicode_table=".var_export($this->unicode_table,true).";?>");
		@fclose($fp);
	}
Beispiel #8
0
	function install()
	{
		$this->CheckAdminPrivs('upgrade');
		@set_time_limit(120);
		$version=$this->Post['version']?$this->Post['version']:$this->Get['version'];
		$step=$this->Get['step'];
		$status=(int)$this->Get['status'];		if(empty($version))$this->Messager("参数错误");
		$odver = get('odver') ? get('odver') : SYS_VERSION;
		$url="admin.php?mod=upgrade&code=install&version=$version&odver=$odver";
				$upgrade_data_dir = DATA_PATH.'upgrade/';
		$upcName = $odver.'~'.$version;
		$upgrade_file = $upgrade_data_dir.$upcName.".zip";
		if (is_file($upgrade_file)==false)
		{
			$this->Messager("升级包已经不存在,请重新下载", null);
		}
		$upgrade_tmp_dir = $upgrade_data_dir.$odver.'~'.$version.'/';
		is_dir($upgrade_tmp_dir) || @tmkdir($upgrade_tmp_dir);

		include_once(LIB_PATH.'io.han.php');

				if($step=='check')
		{
			$quick = $this->Get['quick'];
			$check_url=$url."&step=check&quick={$quick}";
			if($status===0) $this->Messager("正在释放临时文件...",$check_url.'&status=1',0);
			$files = logic('upgrade')->zip2web($upgrade_file, $upgrade_tmp_dir);
			isset($files['__extract_error__']) && $this->Messager($files['__error_string__'], null);
			$backup_url=$url."&step=backup";
			if ($quick == 'yes')
			{
				$this->Messager('正在开始升级...', $backup_url, 0);
			}
			include handler('template')->file('@admin/upgrade_change_list');
			exit;
		}

				if ($step=='backup')
		{
			logic('upgrade')->upgrade2start();

			$original_path=ROOT_PATH;			$backup_path=ROOT_PATH.'backup/'.SYS_VERSION.'-'.SYS_BUILD.'/';			if(!is_dir($backup_path)) {
				IoHandler::MakeDir($backup_path,0777);
			}
			clearstatcache();

			$error_found = logic('upgrade')->web2backup($upgrade_tmp_dir, $backup_path);
			if ($error_found == 'ok')
			{
				$error_found = logic('upgrade')->web2upgrade($upgrade_tmp_dir, $original_path);
			}
			if ($error_found != 'ok')
			{
				$msg = '<div style="width:700px;text-align:left;">备份或者升级网站文件时出错,程序无法继续执行!<hr/>';
				$msg .= $error_found;
				$msg .= '<hr/>请您检查相应文件权限后,<a href="'.$url.'&step=backup">点击此处</a> 重新升级';
				$msg .= '</div>';
				$this->Messager($msg, null);
			}
			$this->Messager("正在升级中,请勿关闭窗口...", $url, 0);
		}
				logic('upgrade')->upgrade2data($upgrade_tmp_dir);
				logic('upgrade')->upgrade2update($upgrade_tmp_dir, $original_path);
				logic('upgrade')->upgrade2clear($upcName);
				logic('upgrade')->upgrade2finish();
				$msg="升级已经完成! <br/><br/><a href='admin.php?mod=index&code=home'>返回后台首页</a>";
		$this->Messager($msg, null);
	}
Beispiel #9
0
	function CopyDir($from, $to, $children = true)
	{
		if(is_dir($from) == false)Return false;
		if(is_dir($to) == false)
		{
			if(IoHandler::MakeDir($to) == false)
			{
				Return false;
			}
		}
		$from_handle = opendir($from);
		while(($file = readdir($from_handle)) !== false)
		{
			if($file != '.' and $file != '..')
			{
				$from_abs_path = $from . '/' . $file;
				$to_abs_path = $to . '/' . $file;
				if(is_dir($from_abs_path) != false and $children == true)
				{
					IoHandler::MakeDir($to_abs_path);
					IoHandler::CopyDir($from_abs_path, $to_abs_path, $children);
				}
				if(is_file($from_abs_path) != false)
				{
					if(copy($from_abs_path, $to_abs_path) == false)
					{
						Return false;
					}
				}
			}
		}
		closedir($from_handle);
		Return true;
	}
Beispiel #10
0
 function UploadAvatorFromApp()
 {
     $this->NoLoginAjaxReturn();
     $rpath = './images/temp';
     $IoHandler = new IoHandler();
     $Images = new ImagesHandler('Filedata');
     $Images->saveDir = $rpath;
     $path = $Images->move_uploaded();
     if (!file_exists($path)) {
         $result['status'] = "failed";
         $result['message'] = urlencode('头像裁剪失败,图片传输过程中丢失');
         echo urldecode(json_encode($result));
         exit;
     }
     $userInfo = $this->UserLogic->GetUser($this->User['uid']);
     $old_facePath = $userInfo["face_url"];
     $imgId = $this->ImgLogic->AddNewImage();
     $path1 = 'images/user/' . face_path($imgId);
     if (!file_exists($path1)) {
         $IoHandler->MakeDir($path1);
     }
     $prefix = $path1 . $imgId;
     resizeimage($path, $prefix . '_p.jpg', 180, 180, true);
     resizeimage($path, $prefix . '_s.jpg', 50, 50, true);
     //$IoHandler->CopyFile($path, $prefix.'_t.jpg');
     if (file_exists($prefix . '_s.jpg')) {
         $userdata = array();
         $userdata['face_url'] = $prefix . '_s.jpg';
         $ret = $this->UserLogic->UpdateUser2($userdata, $this->User['uid']);
         if ($old_facePath && $old_facePath != "" && file_exists($old_facePath)) {
             $IoHandler->DeleteFile($old_facePath);
             $ps = explode("_", $old_facePath);
             $old2 = $ps[0] . "_p.jpg";
             if (file_exists($old2)) {
                 $IoHandler->DeleteFile($old2);
             }
         }
     } else {
         $result['status'] = "failed";
         $result['message'] = urlencode('头像缩放出错');
         $result['item'] = $prefix . '_s.jpg';
         echo urldecode(json_encode($result));
         exit;
     }
     $this->ImgLogic->DeleteImage($imgId, "");
     $IoHandler->DeleteFile($path);
     $result['status'] = "ok";
     $result['face_url'] = $prefix . '_s.jpg';
     $result['message'] = urlencode('头像保存成功');
     echo urldecode(json_encode($result));
 }