forked from cynial/STBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditor.php
More file actions
83 lines (74 loc) · 2.13 KB
/
Editor.php
File metadata and controls
83 lines (74 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
/*
* Plugin Name: ckeditor编辑器
* Plugin URI: http://www.cnsaturn.com/
* Description: 一个优秀的所见即所得编辑器
* Version: 0.1
* Author: Saturn
* Author Email: [email protected]
*/
class Editor
{
public function __construct(&$plugin)
{
//第三方可视化编辑器必须注册的钩子之一:实例化编辑器
$plugin->register(ST_CORE_HOOK_EDITOR, $this, 'render');
//第三方可视化编辑器必须注册的钩子之二:上传附件插入编辑器
$plugin->register(ST_CORE_HOOK_EDITOR_INSERT_ATTACH, $this, 'insert_attachment');
$plugin->register(ST_CORE_HOOK_EDITOR_INSERT_MORE, $this, 'insert_more');
}
public function render()
{
$url = base_url() . ST_PLUGINS_DIR . '/editor/';
echo <<<EOT
<script language="javascript" type="text/javascript" src="{$url}ckeditor/ckeditor.js"></script>
<script type="text/javascript">
CKEDITOR.replace('text');
</script>
EOT;
}
public function insert_attachment()
{
echo <<<EOT
var insertImageToEditor = function (title, url, link) {
if ( CKEDITOR.instances.text.mode == 'wysiwyg' ) {
CKEDITOR.instances.text.insertHtml('<img src=\"' + url + '\" alt=\"' + title + '\" />') ;
}
else
{
alert('请先转换到所见即所得模式') ;
}
};
var insertLinkToEditor = function (title, url, link) {
if ( CKEDITOR.instances.text.mode == 'wysiwyg' ) {
CKEDITOR.instances.text.insertHtml('<a href=\"' + url + '\" title=\"' + title + '\">' + title + '</a>') ;
}
else
{
alert('请先转换到所见即所得模式') ;
}
};
EOT;
}
public function insert_more()
{
echo <<<EOT
<script type="text/javascript">
function InsertHTML(value)
{
// Get the editor instance that we want to interact with.
var oEditor = CKEDITOR.instances.text;
// Check the active editing mode.
if (oEditor.mode == 'wysiwyg' )
{
// Insert the desired HTML.
oEditor.insertHtml( value ) ;
}
else
alert( '请先转换到所见即所得模式' ) ;
}
</script>
<a href="javascript: InsertHTML('[--break--]');" title="用于割断长内容在列表页的显示和Feed摘要输出">插入摘要分割符</a>
EOT;
}
}