<?php
if(!isset($type)){exit();}
$this->showhd("操作台");
$edit=0;
if(isset($_GET["aid"])){
$aid=$_GET["aid"];
$sql=$this->sql("select `title`,`content` from `art` where `aid`='".$this->res($aid)."'");
if($this->num($sql)==1){
$r=$this->row($sql);
$title=$r[0];
$content=$r[1];
$edit=1;
}
}
?>
<style type="text/css">
.gg{height:40px;position:fixed;width:100%;left:0px;text-indent:10px;top:0px;background-color:#fff;border-bottom:1px solid #f1f1f1;z-index:33;}
.gg a{line-height:40px;display:inline-block;height:40px;}
.gg span{font-weight:bold;}
.ggar{float:right;margin-right:8px;}
.ggar img{width:24px;height:24px;margin-top:8px;}
.ggal{float:left;margin-left:8px;}
</style>
<div style="height:41px;"></div>
<div class='gg'>
<a href='/?type=ht&type2=artadd' class='ggal'>管理内容</a>
<?php if($_SESSION["rank"]==1){ ?>
<a href='/?type=ht&type2=config' class='ggar'><img src='/public/img/config.png'/></a>
<a href='/?type=ht&type2=useradd' class='ggar'><img src='/public/img/useradd.png'/></a>
<?php } ?>
<a href='/?type=ht&type2=pw' class='ggar'><img src='/public/img/pw.png'/></a>
</div>
<script src="/public/localResizeIMG.js" type="text/javascript"></script>
<script src="/public/mobileBUGFix.mini.js" type="text/javascript"></script>
<script src="/public/jquery.lazyload.js"></script>
<Style>
.acbox2{width:100%;z-index:34;margin-top:10px;}
.acbox21{margin:9px auto;}
.acbox22{margin:10px;padding:0px 10px 10px 10px; background-color:#fff;border-radius:10px;}
.acbox221{height:50px;}
.acbox221 a{display:inline-block;height:30px;line-height:30px;margin-top:10px;border-radius:5px;color:#fff;font-size:18px;font-weight:bold;padding:0px 8px 0px 8px;}
.acbox221 .accl{background-color:#515151;float:left;}
.acbox221 .acok{background-color:#d4237a;float:left;}
.acbox221 .acok2{background-color:green;float:left;}
.intype{line-height:40px;}
.intel{border-radius:5px;border:1px solid #999999;margin:5px 1px 0px 1px;height:35px;background-color:#fff;padding-left:5px;padding-right:5px;}
.intel input{border:0px;padding:0px;width:100%;background-color:#fff;padding-bottom:10px;padding-top:10px;height:15px;}
.insos{color:red;line-height:30px;}
#editable{border-radius:5px;border:1px solid #999999;margin:5px 1px 0px 1px;background-color:#fff;padding:5px;line-height:30px;min-height:180px;background-color:#fff;}
#editable p{margin-top:5px;}
#editable img{width:150px;}
.ggar2{float:left;margin-right:18px;width:34px;position:relative;}
.ggar2 img{width:24px;height:24px;margin-top:8px;}
.file2{height:35px;position:absolute;top:0px;left:0px;opacity:0;cursor:pointer;}
.file2 input {font-size:100px;cursor:pointer;}
</Style>
<div class='mmm'>
<div class='mmm2'>
<div class='mmm21'>
<Div class='acbox2 acboxh'><Div class='acbox21'><Div class='acbox22'>
<div class="intel"><input id='title' placeholder='标题' value='<?php if($edit==1){echo $title;} ?>'/></div>
<div class="gn">
<a href='#' class='ggar2 unlink'><img src='/public/img/unlink.png'/></a>
<a href='#' class='ggar2 link'><img src='/public/img/link.png'/></a>
<a href='#' class='ggar2 xigua'><img src='/public/img/xigua.png'/></a>
<a href='#' class='ggar2'><img src='/public/img/shopgoodpic.png'/><div class="file2"><input type="file" /></div></a>
</div>
<script>
$(function(){
$(".link").click(function(){
var url = window.prompt("请在编辑器里输入文本再选中再点添加链接", '');
if(url!="" && url!=null){
document.execCommand("CreateLink","false",url);
}
return false;
});
$(".unlink").click(function(){
document.execCommand("unLink");
return false;
});
$(".xigua").click(function(){
$("#editable").focus();
var url = window.prompt("视频inframe链接(推荐用bilibili)", '');
if(url!="" && url!=null){
insertHtmlAtCaret('<iframe width="100%" height="60%" style="min-height:350px;" src="'+url+'" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe>');
}
return false;
});
});
</script>
<div id="editable" contenteditable="true" ><?php if($edit==1){echo $content;} ?></div>
<Div class='acbox221'><a href='#' class='acok pb'>确认发布</a></Div>
<div></div></Div>
</div>
</div>
</div>
<script type="text/javascript">
var base64v;
$('input:file').localResizeIMG({
width: 360,
quality: 0.8,
success: function (result) {
var img = new Image();
base64v=img.src = result.base64;
$("#editable").focus();
insertHtmlAtCaret("<div class='imgs'><img src='"+base64v+"'/></div>");
}
});
var base64;
window.onload=function() {
function paste_img(e) {
debugger;
if ( e.clipboardData.items ) {
// google-chrome
ele = e.clipboardData.items
for (var i = 0; i < ele.length; ++i) {
if ( ele[i].kind == 'file' && ele[i].type.indexOf('image/') !== -1 ) {
var blob = ele[i].getAsFile();
var isImg=(blob&&1)||-1;
var reader=new FileReader();
if(isImg>=0){
//将文件读取为 DataURL
reader.readAsDataURL(blob);
}
reader.onload=function(event){
base64=event.target.result;
dealImage(base64, 600, useImg);
}
}
}
} else {
alert('non-chrome');
}
}
document.getElementById('editable').onpaste=function(e){
ele2 = e.clipboardData.items ;
var el=ele2.length;
if(el==1 && ele2[0].type.indexOf('image/') !== -1){
paste_img(event);return false;
}
if(el==2 && ele2[1].type.indexOf('image/') !== -1){
paste_img(event);return false;
}
}
}
function dealImage(base64, w, callback) {
var newImage = new Image();
var quality = 0.8; //压缩系数0-1之间
newImage.src = base64;
newImage.setAttribute("crossOrigin", 'Anonymous'); //url为外域时需要
var imgWidth, imgHeight;
newImage.onload = function () {
//imgWidth = 500;
if(this.width>500){
imgWidth = 500;
imgHeight =(500/this.width)*this.height;
}else{
imgWidth = this.width;
imgHeight = this.height;
}
//imgHeight = 500;
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
if (Math.max(imgWidth, imgHeight) > w) {
if (imgWidth > imgHeight) {
canvas.width = w;
canvas.height = w * imgHeight / imgWidth;
} else {
canvas.height = w;
canvas.width = w * imgWidth / imgHeight;
}
} else {
canvas.width = imgWidth;
canvas.height = imgHeight;
quality = 0.8;
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(this, 0, 0, canvas.width, canvas.height);
var base64 = canvas.toDataURL("image/jpeg", quality); //压缩语句