<?php
/*
Version: 2025.05.02
Plugin Name: TinyMCE编辑器
Plugin URL: https://www.emlog.net/plugin/detail/362
Description: 所见即所得编辑器，图片、视频、音频、文件批量上传，嵌入媒体外链代码，Ctrl+Enter快捷保存。媒体嵌入：AcFun、BiliBili、抖音、优酷、搜狐视频、腾讯视频、西瓜视频、网易云音乐。
*/
!defined('EMLOG_ROOT') && exit('access deined!');
addAction('adm_head',function(){
if(!in_array(strrchr($_SERVER['SCRIPT_NAME'],'/'),array('/article.php','/page.php','/twitter.php'))){return false;}
echo '
<style>
.tox-tbtn:not(.tox-tbtn--select):not(.tox-split-button__chevron) {width: 32px !important;}
.tox-tbtn__select-chevron, tox-split-button__chevron {width: 16px !important;}
.tox-tbtn__select-label {width: auto !important;}
</style>
';
});
addAction('adm_footer',function(){
if(!in_array(strrchr($_SERVER['SCRIPT_NAME'],'/'),array('/article.php','/page.php','/twitter.php'))){return false;}
$fold=substr(basename(__FILE__),0,-4);
echo '
<script>
var emlog_tinymce_area=document.createElement(\'textarea\');
var emlog_tinymce_type=[\'.'.implode('\',\'.',Option::getAttType()).'\'];
var emlog_tinymce_size='.Option::getAttMaxSize().';
$(function(){
if(typeof(Editor)!=\'undefined\'){
let officialEditor=Editor.editor.find(\'textarea\').first();
emlog_tinymce_area.name=officialEditor.attr(\'name\');
emlog_tinymce_area.value=officialEditor.val();
emlog_tinymce_area.className=\'useTinyMCE\';
Editor.editor.before(emlog_tinymce_area);
Editor.editor.remove();
};
Editor={
getValue:function(){return tinymce.get(emlog_tinymce_area.id).getContent();},
getValueText:function(){return tinymce.get(emlog_tinymce_area.id).getContent({format:"text"});},
getSelection:function(){return tinymce.get(emlog_tinymce_area.id).selection.getContent();},
getSelectionText:function(){return tinymce.get(emlog_tinymce_area.id).selection.getContent({format:"text"});},
setValue:function(c){tinymce.get(emlog_tinymce_area.id).setContent(c);},
insertValue:function(c){tinymce.get(emlog_tinymce_area.id).insertContent(c);},
};
Editor.getHTML=Editor.getValue;
Editor.getPreviewedHTML=Editor.getValue;
Editor.getMarkdown=Editor.getValueText;
emlog_tinymce_conf={'.stripslashes(Storage::getInstance('emlog_tinymce')->getValue('options')).'};
emlog_tinymce_init("../content/plugins/'.$fold.'/core/tinymce.min.js","../content/plugins/'.$fold.'/zh_CN.js");
});
function insert_media_video(fileurl){tinymce.get(emlog_tinymce_area.id).insertContent(emlog_tinymce_html({act:\'video\',source:fileurl}));};
function insert_media_audio(fileurl){tinymce.get(emlog_tinymce_area.id).insertContent(emlog_tinymce_html({act:\'audio\',source:fileurl}));};
function insert_media_img(fileurl,thumburl){tinymce.get(emlog_tinymce_area.id).insertContent(emlog_tinymce_html({act:\'image\',source:fileurl,thumb:thumburl}));};
function insert_media(fileurl,filename){tinymce.get(emlog_tinymce_area.id).insertContent(emlog_tinymce_html({act:\'file\',source:fileurl,alt:filename}));};
$(document).on("focusin",function(e){ // Patch by 曦颜XY
if($(e.target).closest(".tox-textfield").length){e.stopImmediatePropagation();};
if($(e.target).closest(".tox-textarea").length){e.stopImmediatePropagation();};
});
</script>
<script src="../admin/editor.md/lib/marked.min.js"></script>
<script src="../content/plugins/'.$fold.'/yield.js?'.date('Ymd',time()).'"></script>
';
});