<?php

/* ========================================================================
 * $Id: bs.editor.php 2352 2020-07-05 20:21:39Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
#名称：通用编辑器
#标识：bs.editor

class onezphp_bs_editor extends onezphp{
  function __construct(){
    
  }
  function head(){
    $html.='
<script type="text/javascript">
window.UEDITOR_HOME_URL = "'.onez()->homepage().substr(onez('ueditor')->path,strlen(ONEZ_ROOT)).'/lib/";
</script>';
    if($arr['full']){
      $html.=onez('ui')->js(onez('ueditor')->url.'/lib/ueditor.config.js');
    }else{
      $html.=onez('ui')->js(onez('ueditor')->url.'/lib/ueditor.common.js');
    }
    $html.=onez('ui')->js(onez('ueditor')->url.'/lib/ueditor.all.js');
    return $html;
  }
  function form_code($arr){
    $this->arr=$arr;
    $html='';
    #只加载一次
    $height=$arr['height'];
    !$height && $height='600';
    $keyId='editor-'.uniqid();
    $url='?_p=bs.editor&_m=iframe&full='.$arr['full'].'&keyId='.$keyId.'&height='.$height;
    //$html.='<div class="bs-editor"><textarea style="display:none" id="'.$keyId.'" name="'.$arr['key'].'">'.$arr['value'].'</textarea><iframe width="100%" id="'.$keyId.'-iframe" height="'.$height.'" frameborder="0" src="'.$url.'"></iframe></div>';
    
    $html.='<div class="bs-editor"><textarea id="'.$keyId.'" name="'.$arr['key'].'" style="height:'.$height.'px">'.$arr['value'].'</textarea></div>';
    $html.=<<<ONEZ
<script type="text/javascript">
var ue = UE.getEditor('$keyId', {
  autoHeight: true
});
</script>
ONEZ;
    return $html;
  }
  function iframe(){
    $form=onez('factory.form');
    $height=onez()->gp('height');
    $full=onez()->gp('full');
    $keyId=onez()->gp('keyId');
    $form->add(array('label'=>'','key'=>'content','type'=>'kindeditor','height'=>$height-10,'full'=>$full,'ptoken'=>'ueditor',)); 
    echo'<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title><style>
*{font-family:"Microsoft Yahei","Source Sans Pro",sans-serif}
.ke-statusbar{display:none}</style>'.onez('jquery')->head(1).'
<script type="text/javascript">
window.onez={};
window.keyId="'.$keyId.'";
</script>
	</head>
	<body style="overflow:hidden;margin:0;padding:5px" scroll="no">'.$form->code(array('submit'=>false)).'</body>
</html>';
  }
  function value($key){
    return $_REQUEST[$key];
  }
  function form_save(&$value,$arr=false){
    global $G;
    !$arr && $arr=$this->arr;
    $value=$_REQUEST[$arr['key']];
  }
}