Home Backend Development PHP Tutorial phpcms v9编辑器ckeditor数据恢复效能

phpcms v9编辑器ckeditor数据恢复效能

Jun 13, 2016 pm 01:13 PM
echo gt javascript lt php

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 ;
Copy after login

注意:表前缀和数据库编码,推荐自己手工用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();
	}
}
?>
Copy after login


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');
?>
Copy after login


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');
		}
}
?>
Copy after login


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>


Copy after login


完毕.2011-11-12 for http://www.xiaojudeng.com,转载请注明出处,谢谢.
Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

See all articles