search
HomeBackend DevelopmentPHP Tutorial phpcms v9编辑器ckeditor数据恢复效能

phpcms v9编辑器ckeditor数据恢复功能
为phpcms v9的ckeditor编辑器开发的数据恢复功能.下面直接上步骤说明吧.
1.\statics\js\ckeditor\config.js文件最后增加以下代码:

//化蝶自在飞 add 2011-11-12 自动保存数据
var timer = counttimer = '30';//每?秒保存一次
var delays = 10;//延迟多少秒执行,因为firefox下无法显示,建议设置为10000
var editorid = 'content';
var fromid = 'myform';
$(function(){
var str = '<a href="javascript:void(0);" onclick="open_databak();return false;">恢复数据</a><span id="tuzwu_timer">'+timer+'</span>秒后自动保存';
setTimeout('$(".cke_footer").append(\''+str+'\')',delays*1000);
setInterval('tuzwu_posts()',timer*1000);
setInterval('tuzwu_timer()',1000);
});
function tuzwu_posts(){ //post提交数据
var editor = CKEDITOR.instances[editorid];
data = editor.getData();
$('#'+editorid).val(data);
$.post("api.php?op=editor_data", $("#"+fromid).serializeArray(),function(data){
$('#'+editorid).val();
});
}
function tuzwu_timer(){ //每秒执行1次,倒数计时
if(timer<br><br>2.建数据表用于保存数据:<br><pre name="code" class="java">
CREATE TABLE `v9_editor_data` (
  `id` mediumint(8) NOT NULL auto_increment,
  `data` mediumtext character set gbk NOT NULL COMMENT '数据',
  `time` int(10) NOT NULL,
  `userid` mediumint(8) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

注意:表前缀和数据库编码,推荐自己手工用phpmyadmin建表;

3.\phpcms\model\editor_data_model.class.php新建该文件,用以下代码填充文件:
<?php defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_sys_class('model', '', 0);
class editor_data_model extends model {
	public function __construct() {
		$this->db_config = pc_base::load_config('database');
		$this->db_setting = 'default';
		$this->table_name = 'editor_data';
		parent::__construct();
	}
}
?>


4.\api\editor_data.php新建改文件,用以下代码填充该文件:
<?php defined('IN_PHPCMS') or exit('No permission resources.');
header('Content-type: text/html; charset=utf-8');
$db = pc_base::load_model('editor_data_model');
$_userid = param::get_cookie('userid');
if(!$_POST['info']['content']) exit('0');
$postinfo = array2string($_POST['info']);
$postdata = CHARSET != 'utf-8' ? iconv('utf-8', CHARSET, $postinfo ):$postinfo;
$posts = array(
'data'=>$postdata,
'userid'=>$_userid,
'time'=>SYS_TIME
);
$r = $db->get_one( array('userid'=>$_userid,'data'=>$postdata),'id' );//如果没有改变就不用备份
if($r) exit('0');
$db->insert($posts);
exit('1');
?>


5.\phpcms\modules\content\databak.php新建该文件,代码如下:
<?php defined('IN_PHPCMS') or exit('No permission resources.');
//模型缓存路径
define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
pc_base::load_app_func('util','content');
pc_base::load_app_class('admin','admin',0);
class databak extends admin {
	private $db;
	function __construct() {
		$this->db = pc_base::load_model('editor_data_model');
		$this->_userid = param::get_cookie('userid')?param::get_cookie('userid'):param::get_cookie('admin_userid');
		$this->_username = param::get_cookie('_username');
		$this->_groupid = param::get_cookie('_groupid');
	}

		public function init() {
        if(!$this->_userid) exit('用户ID校验失败');
		$page = $_GET['page']?$_GET['page']:1;
		$infos = $this->db->listinfo( array('userid'=>$this->_userid),'time DESC',$page,20,'',10 );
        $pages = $this->db->pages;
		$target = $_GET['target'];
		include $this->admin_tpl('databak');
		}
}
?>


6.\phpcms\modules\content\templates\databak.tpl.php新建改文件,代码如下:
<?php header('Content-Type:text/html;charset=utf-8');
defined('IN_ADMIN') or exit('No permission resources.');
$show_dialog = 1;
?>

 class="addbg"<?php } ?>>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7">
<title><?php echo L('website_manage');?></title>
<link href="<?php%20echo%20CSS_PATH?>reset.css" rel="stylesheet" type="text/css">
<link href="<?php%20echo%20CSS_PATH.SYS_STYLE;?>-system.css" rel="stylesheet" type="text/css">
<link href="<?php%20echo%20CSS_PATH?>table_form.css" rel="stylesheet" type="text/css">
<?php if(isset($show_dialog)) {
?>
<link href="<?php%20echo%20CSS_PATH?>dialog.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="<?php%20echo%20JS_PATH?>dialog.js"></script>
<?php } ?>
	<link rel="stylesheet" type="text/css" href="<?php%20echo%20CSS_PATH?>style/<?php%20echo%20SYS_STYLE;?>-styles1.css" title="styles1" media="screen">
	<link rel="alternate stylesheet" type="text/css" href="<?php%20echo%20CSS_PATH?>style/<?php%20echo%20SYS_STYLE;?>-styles2.css" title="styles2" media="screen">
	<link rel="alternate stylesheet" type="text/css" href="<?php%20echo%20CSS_PATH?>style/<?php%20echo%20SYS_STYLE;?>-styles3.css" title="styles3" media="screen">
    <link rel="alternate stylesheet" type="text/css" href="<?php%20echo%20CSS_PATH?>style/<?php%20echo%20SYS_STYLE;?>-styles4.css" title="styles4" media="screen">
<script language="javascript" type="text/javascript" src="<?php%20echo%20JS_PATH?>jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="<?php%20echo%20JS_PATH?>admin_common.js"></script>
<script language="javascript" type="text/javascript" src="<?php%20echo%20JS_PATH?>styleswitch.js"></script>
<?php if(isset($show_validator)) { ?>
<script language="javascript" type="text/javascript" src="<?php%20echo%20JS_PATH?>formvalidator.js" charset="UTF-8"></script>
<script language="javascript" type="text/javascript" src="<?php%20echo%20JS_PATH?>formvalidatorregex.js" charset="UTF-8"></script>
<?php } ?>
<script type="text/javascript">
	window.focus();
	var pc_hash = '<?php echo $_SESSION['pc_hash'];?>';
	<?php if(!isset($show_pc_hash)) { ?>
		window.onload = function(){
		var html_a = document.getElementsByTagName('a');
		var num = html_a.length;
		for(var i=0;i<num;i++) {
			var href = html_a[i].href;
			if(href && href.indexOf('javascript:') == -1) {
				if(href.indexOf('?') != -1) {
					html_a[i].href = href+'&pc_hash='+pc_hash;
				} else {
					html_a[i].href = href+'?pc_hash='+pc_hash;
				}
			}
		}

		var html_form = document.forms;
		var num = html_form.length;
		for(var i=0;i<num;i++) {
			var newNode = document.createElement("input");
			newNode.name = 'pc_hash';
			newNode.type = 'hidden';
			newNode.value = pc_hash;
			html_form[i].appendChild(newNode);
		}
	}
<?php } ?>
</script>


<?php if(!isset($show_header)) { ?>
<th>备份生成时间</th>
			<th>标题</th>
		
	
<tbody>
<?php if(is_array($infos)){
	foreach($infos as $info){
	$data = string2array(CHARSET != 'utf-8' ? iconv( CHARSET,'utf-8', $info['data'] ):$info['data']);
	$info['title'] = $data['title'] ? $data['title'] : '暂无标题';
	$jsondata = json_encode($data);
		?>
	<tr onclick="return_id(<?php echo $info['id'];?>)" style="cursor:hand" title="请选择">
	<script language="JavaScript">
var jsondata<?php echo $info['id'];?> = [<?php echo $jsondata;?>];
	</script>
	<td width="40%"><?php echo date("Y-m-d h:i:s",$info['time']);?></td>
		<td><?php echo $info['title']?></td>
		
	</tr>
	<?php }
}
?>
</tbody>

<div id="pages">
<?php echo $pages?>
<div style="text-align:right;">by 化蝶自在飞</div>
</div>
<script language="JavaScript">
	function return_id(id) {
    var objstr = eval('jsondata'+ id);
	for(x in objstr[0]){
	value = eval('objstr[0].'+x);
	if(x == 'content') { //编辑器特殊对待
	var editorid = 'content';
	var editor = window.top.CKEDITOR.instances[editorid];
    editor.setData(value);
	}
	if( window.top.$('#'+x) ) window.top.$('#'+x).val( value );
	}
}
</script>




完毕.2011-11-12 for http://www.xiaojudeng.com,转载请注明出处,谢谢.
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Beyond the Hype: Assessing PHP's Role TodayBeyond the Hype: Assessing PHP's Role TodayApr 12, 2025 am 12:17 AM

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

What are Weak References in PHP and when are they useful?What are Weak References in PHP and when are they useful?Apr 12, 2025 am 12:13 AM

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

Explain the __invoke magic method in PHP.Explain the __invoke magic method in PHP.Apr 12, 2025 am 12:07 AM

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

Explain Fibers in PHP 8.1 for concurrency.Explain Fibers in PHP 8.1 for concurrency.Apr 12, 2025 am 12:05 AM

Fibers was introduced in PHP8.1, improving concurrent processing capabilities. 1) Fibers is a lightweight concurrency model similar to coroutines. 2) They allow developers to manually control the execution flow of tasks and are suitable for handling I/O-intensive tasks. 3) Using Fibers can write more efficient and responsive code.

The PHP Community: Resources, Support, and DevelopmentThe PHP Community: Resources, Support, and DevelopmentApr 12, 2025 am 12:04 AM

The PHP community provides rich resources and support to help developers grow. 1) Resources include official documentation, tutorials, blogs and open source projects such as Laravel and Symfony. 2) Support can be obtained through StackOverflow, Reddit and Slack channels. 3) Development trends can be learned by following RFC. 4) Integration into the community can be achieved through active participation, contribution to code and learning sharing.

PHP vs. Python: Understanding the DifferencesPHP vs. Python: Understanding the DifferencesApr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP: Is It Dying or Simply Adapting?PHP: Is It Dying or Simply Adapting?Apr 11, 2025 am 12:13 AM

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The Future of PHP: Adaptations and InnovationsThe Future of PHP: Adaptations and InnovationsApr 11, 2025 am 12:01 AM

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.