├── wp2pcs
├── cache.dir
│ └── README.md
├── temp.dir
│ └── README.md
├── assets
│ ├── about.png
│ ├── dir-bg.png
│ ├── file-bg.png
│ ├── loading.gif
│ ├── image-bg.png
│ ├── music-bg.png
│ ├── javascript.js
│ ├── insert-media.css
│ ├── manage-media.css
│ ├── manage-media.js
│ └── insert-media.js
├── hook
│ ├── clean-temp.php
│ ├── copyright.php
│ ├── uninstall.php
│ ├── install.php
│ ├── refresh-token.php
│ ├── auto-backup.php
│ ├── load.php
│ └── insert-media.php
├── action
│ ├── general.php
│ ├── load.php
│ └── backup.php
├── README.md
├── config.php
├── readme.txt
├── wp2pcs.php
├── menu.php
├── admin
│ ├── about.php
│ ├── general.php
│ ├── backup.php
│ └── load.php
└── libs
│ ├── functions.backup.php
│ ├── functions.php
│ ├── DatabaseUtil
│ └── DBTool.class.php
│ ├── FileUtil
│ └── FileZIP.class.php
│ └── BaiduPCS_PHP_SDK
│ └── BaiduPCS.class.php
├── README.md
└── oauth-server
├── config.php
├── README.md
├── BaiduLibs
├── BaiduException.php
├── BaiduOAuth2.php
├── BaiduStore.php
├── Baidu.php
├── BaiduUtils.php
├── BaiduApiClient.php
├── BaiduPCS.class.php
└── RequestCore.class.php
├── client-baidu-refresh-token.php
└── client-baidu-oauth.php
/wp2pcs/cache.dir/README.md:
--------------------------------------------------------------------------------
1 | 目录必须要有可写权限
--------------------------------------------------------------------------------
/wp2pcs/temp.dir/README.md:
--------------------------------------------------------------------------------
1 | 目录必须要有可写权限
2 |
--------------------------------------------------------------------------------
/wp2pcs/assets/about.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangshuang/wp2pcs/HEAD/wp2pcs/assets/about.png
--------------------------------------------------------------------------------
/wp2pcs/assets/dir-bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangshuang/wp2pcs/HEAD/wp2pcs/assets/dir-bg.png
--------------------------------------------------------------------------------
/wp2pcs/assets/file-bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangshuang/wp2pcs/HEAD/wp2pcs/assets/file-bg.png
--------------------------------------------------------------------------------
/wp2pcs/assets/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangshuang/wp2pcs/HEAD/wp2pcs/assets/loading.gif
--------------------------------------------------------------------------------
/wp2pcs/assets/image-bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangshuang/wp2pcs/HEAD/wp2pcs/assets/image-bg.png
--------------------------------------------------------------------------------
/wp2pcs/assets/music-bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangshuang/wp2pcs/HEAD/wp2pcs/assets/music-bg.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WP2PCS
2 |
3 | 将你的网站定时自动备份到百度网盘。
4 |
5 | ## 使用方法
6 |
7 | 1) 安装oauth-server,阅读[这里](./oauth-server)
8 |
9 | 2) 安装插件,阅读[这里](./wp2pcs)
10 |
--------------------------------------------------------------------------------
/wp2pcs/hook/clean-temp.php:
--------------------------------------------------------------------------------
1 | '."\n";
6 | }
--------------------------------------------------------------------------------
/oauth-server/config.php:
--------------------------------------------------------------------------------
1 | $page_name,'time'=>time()),$page_url));
10 | }
--------------------------------------------------------------------------------
/oauth-server/README.md:
--------------------------------------------------------------------------------
1 | # WP2PCS的授权服务器代码
2 |
3 | 先在你的服务器上面创建一个网站,绑定域名,比如说`api.papapa.com`。
4 |
5 | 然后修改config.php里面的内容,百度的PCS API要你自己申请。
6 |
7 | 修改完之后,上传到`api.papapa.com`,访问以下`api.papapa.com/client-baidu-oauth.php`试试看,如果能够访问得到,说明服务器搭建好了。
8 |
9 | 修改wp2pcs插件的config.php中的`WP2PCS_API_URL`的域名为`api.papapa.com`,这样当你在你的WordPress后台点击授权的时候,就会进入`api.papapa.com`进行授权的跳转。登录百度账号后跳转回你的WordPress后台,授权就成功了。
10 |
11 | `api.papapa.com`可以作为你自己任何WordPress的授权服务器,你不需要搭建多个授权服务器,而只需要把wp2pcs插件上传到不同的WordPress去使用即可。
12 |
13 | **注意**:不要公开给别人使用,wp2pcs就是这样被封掉的。作为开发者,更希望你用它来做备份。
14 |
--------------------------------------------------------------------------------
/wp2pcs/README.md:
--------------------------------------------------------------------------------
1 | # WP2PCS
2 |
3 | 将网站数据和文件定时自动备份到百度云盘的WordPress插件。
4 |
5 | ## Dependences
6 |
7 | 环境要求:
8 |
9 | * php 5.6+
10 | * wordpress 4.0+
11 | * curl (full module)
12 | * rewrite mod if you want to use permalink (nginx is not suite for virtual file permalink)
13 |
14 | 使用老版本 [v1.5.5](https://github.com/tangshuang/WP2PCS/releases/tag/v1.5.5) please.
15 |
16 | ## Install
17 |
18 | 先下载整个wp2pcs到你的电脑,然后处理[oauth-server](../oauth-server),处理完之后修改config.php,把里面的`WP2PCS_API_URL`修改为你的授权服务器的域名,把`WP2PCS_BAIDUPCS_REMOTE_DIR`改为百度开发者中心的应用名称。保存之后,上传wp2pcs目录到你的WordPress插件目录下,然后到WordPress后台启用wp2pcs插件。
19 |
20 | ## Active
21 |
22 | 在WordPress后台启用wp2pcs插件之后,你需要进行百度账号授权。进入后台"设置-WP2PCS",点击“百度授权”按钮。页面跳转授权之后,就可以对定时备份进行设置。
23 |
--------------------------------------------------------------------------------
/wp2pcs/hook/install.php:
--------------------------------------------------------------------------------
1 | permalink_structure) {
13 | $linktype = 0;
14 | }
15 | }
16 | update_option('wp2pcs_load_linktype',$linktype);
17 | // 更新是否插入图片链接
18 | update_option('wp2pcs_load_imglink',$_POST['wp2pcs_load_imglink']);
19 | // 更新采用站点目录还是共享目录作为默认目录
20 | update_option('wp2pcs_load_remote_dir',$_POST['wp2pcs_load_remote_dir']);
21 | wp_redirect(add_query_arg(array('tab'=>$page_name,'time'=>time()),$page_url));
22 | }
--------------------------------------------------------------------------------
/wp2pcs/config.php:
--------------------------------------------------------------------------------
1 | $update_time + 2*3600) {
7 | wp2pcs_refresh_baidu_token();
8 | }
9 | }
10 |
11 | add_action('wp2pcs_hourly_check_cron_task','wp2pcs_refresh_baidu_token');
12 | function wp2pcs_refresh_baidu_token() {
13 | global $BaiduPCS;
14 | $refresh_token = get_option('wp2pcs_baidu_refresh_token');
15 |
16 | $meta = json_decode($BaiduPCS->getQuota());
17 | if(isset($meta->error_code) && in_array($meta->error_code,array(100,110,111,31023))) {
18 | $data = wp2pcs_curl(WP2PCS_API_URL.'/client-baidu-refresh-token.php',array('refresh_token' => $refresh_token));
19 | $data = json_decode($data);
20 | if(isset($data->access_token) && isset($data->refresh_token)) {
21 | update_option('wp2pcs_baidupcs_access_token',$data->access_token);
22 | update_option('wp2pcs_baidupcs_refresh_token',$data->refresh_token);
23 | }
24 | }
25 |
26 | update_option('wp2pcs_baidu_token_update_time',time());
27 | }
28 |
--------------------------------------------------------------------------------
/wp2pcs/action/backup.php:
--------------------------------------------------------------------------------
1 | $page_name,'time'=>time()),$page_url));
22 | }
23 |
--------------------------------------------------------------------------------
/oauth-server/client-baidu-refresh-token.php:
--------------------------------------------------------------------------------
1 | 'refresh_token',
32 | 'refresh_token' => $refresh_token,
33 | 'client_id' => API_BAIDU_APP_KEY,
34 | 'client_secret' => API_BAIDU_SECRET_KEY,
35 | 'scope' => 'netdisk'
36 | );
37 | $data = _curl('https://openapi.baidu.com/oauth/2.0/token',$post);
38 |
39 | ob_clean();
40 | echo $data;
41 | exit;
42 |
--------------------------------------------------------------------------------
/wp2pcs/hook/auto-backup.php:
--------------------------------------------------------------------------------
1 | 0 && $wp2pcs_backup_amount%$backup_file == 0) {
24 | $backup_file = true;
25 | }
26 | else {
27 | $backup_file = false;
28 | }
29 | if($backup_data > 0 && $wp2pcs_backup_amount%$backup_data == 0) {
30 | $backup_data = true;
31 | }
32 | else {
33 | $backup_data = false;
34 | }
35 |
36 | $wp2pcs_backup_amount ++;
37 | update_option('wp2pcs_backup_amount',$wp2pcs_backup_amount);
38 |
39 | wp2pcs_backup_to_baidupcs($backup_file,$backup_data);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/wp2pcs/readme.txt:
--------------------------------------------------------------------------------
1 | === WP2PCS (WordPress连接到云盘) ===
2 | Contributors: 否子戈
3 | Donate link: http://www.wp2pcs.com
4 | Tags:wp2pcs, 数据备份, 资源调用, baidu, cloud storage, PCS, 百度网盘
5 | Requires at least: 3.5.1
6 | Tested up to: 4.6.1
7 | Stable tag: trunk
8 | License: GPLv2 or later
9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html
10 |
11 | 备份WordPress到云盘,调用云盘内的资源到网站使用。
12 |
13 | == Description ==
14 |
15 | 把WordPress和云盘(PCS,个人云存储)连接在一起的插件。它的两项基本功能:将wordpress的数据库、文件定时自动备份到云盘,以防止由于过失而丢失了网站数据;把云盘作为网站的后备箱,存放图片、附件,解决网站空间不够用的烦恼,可以在网站内直接调用云盘上的文件。目前只支持百度云盘。
16 |
17 | 开发与探讨:http://github.com/tangshuang/WP2PCS
18 | 使用中如有疑问请加官方唯一QQ群(292172954)参与讨论。
19 | 技术问题请到官网查看文档,在对应的文档下方留言。
20 |
21 | 说明
22 |
23 | 1、目前本插件只支持百度网盘。
24 | 2、本插件完全免费,同时提供付费服务,满足不同用户的需求。
25 |
26 | 不适用范围
27 |
28 | * 超大型网站(打包压缩后超过G)
29 | * 尽可能不使用在开启MULTISITE的多站点网站
30 | * 没有读写权限或读写权限受限制的空间(如BAE、SAE)
31 | * 服务器memory limit, time limit比较小,又不能自己修改的
32 | * 免费主机、海外主机等性能差或与PCS通信弱的主机
33 |
34 | == Installation ==
35 |
36 | 1、把wp2pcs文件夹上传到/wp-content/plugins/目录
37 | 2、在后台插件列表中启用它
38 | 3、在“插件-WP2PCS”菜单中,点击授权按钮,等待授权跳转
39 | 4、如果授权成功,你会进入到插件的使用页面。
40 | 5、初始化所有信息。
41 | 6、如果授权不成功,点击更新按钮重新授权。
42 |
43 | == Frequently Asked Questions ==
44 |
45 |
46 | == Screenshots ==
47 |
48 | == Changelog ==
49 |
50 | = 1.6.1 =
51 | 精简插件,成为一个轻量级的备份插件,删除广告、通知等不必要的功能,提供一个资源调用开关选项。
52 |
53 | == Upgrade Notice ==
54 |
55 | = 1.6.1 =
56 | 精简插件,成为一个轻量级的备份插件,删除广告、通知等不必要的功能,提供一个资源调用开关选项。
57 |
--------------------------------------------------------------------------------
/wp2pcs/wp2pcs.php:
--------------------------------------------------------------------------------
1 | getLoginUrl('netdisk','page');
22 | echo '';
23 | echo '';
24 | echo '
42 | ').append(DATA),
132 | LIST = $('#wp2pcs-manage-media-page-files',DATA),
133 | NAVI = $('#wp2pcs-manage-media-page-pagenavi',DATA);
134 | $('#wp2pcs-manage-media-page-files').append(LIST.html());
135 | if(NAVI.find('a.next-page').length > 0) {
136 | $pagenavi.html(NAVI.html()).removeAttr('data-ajaxing');
137 | }
138 | else {
139 | $pagenavi.remove();
140 | }
141 | },
142 | error : function() {
143 | $pagenavi.html('下一页').removeAttr('data-ajaxing');
144 | }
145 | });
146 |
147 | } // -- endif --
148 | });
149 | $(document).on('click','#wp2pcs-manage-media-page-pagenavi a.next-page',function(e){
150 | if($(this).parent().attr('data-ajaxing') != 'true') {
151 | e.preventDefault();
152 | $(window).scroll();
153 | return false;
154 | }
155 | });
156 | // 刷新按钮
157 | $('#wp2pcs-manage-media-btn-refresh').click(function(e){
158 | e.preventDefault();
159 | var $this = $(this),
160 | $body = $('#wp2pcs-manage-media-page-content'),
161 | href = $this.attr('href'),
162 | loading = $this.attr('data-loading'),
163 | ajaxing = $this.attr('data-ajaxing');
164 | $('#wp2pcs-manage-media-page-upload').hide();
165 | $('#wp2pcs-manage-media-page-content').fadeIn(500);
166 | close_file_info();
167 | if(ajaxing == 'true') return;
168 | $this.attr('data-ajaxing','true');
169 | $.ajax({
170 | url : href,
171 | dataType : 'html',
172 | type : 'GET',
173 | timeout : 10000,
174 | beforeSend : function() {
175 | $body.html('').append(DATA),
180 | CONTENT = $('#wp2pcs-manage-media-page-content',DATA);
181 | $body.html(CONTENT.html());
182 | $this.removeAttr('data-ajaxing');
183 | },
184 | error : function() {
185 | $this.removeAttr('data-ajaxing');
186 | var cf = confirm('连接超时,强制刷新?');
187 | if(cf) {window.location.reload(false);}
188 | }
189 | });
190 | });
191 |
192 | });
193 |
--------------------------------------------------------------------------------
/wp2pcs/libs/DatabaseUtil/DBTool.class.php:
--------------------------------------------------------------------------------
1 |
6 | * @date 2014-03-17
7 | * Class DatabaseTool
8 | */
9 | class DatabaseTool
10 | {
11 | private $handler;
12 | private $config = array(
13 | 'host' => 'localhost',
14 | 'port' => 3306,
15 | 'user' => 'root',
16 | 'password' => '',
17 | 'database' => 'test',
18 | 'charset' => 'utf8',
19 | 'target' => 'sql.sql'
20 | );
21 | private $tables = array();
22 | private $error;
23 | private $begin; //开始时间
24 | /**
25 | * 架构方法
26 | * @param array $config
27 | */
28 | public function __construct($DB_HOST,$DB_USER,$DB_PASSWORD,$DB_NAME)
29 | {
30 | $config = array(
31 | 'host' => $DB_HOST,
32 | 'user' => $DB_USER,
33 | 'password' => $DB_PASSWORD,
34 | 'database' => $DB_NAME
35 | );
36 | $this->begin = microtime(true);
37 | $config = is_array($config) ? $config : array();
38 | $this->config = array_merge($this->config, $config);
39 | //启动PDO连接
40 | try
41 | {
42 | $this->handler = new PDO("mysql:host={$this->config['host']}:{$this->config['port']};dbname={$this->config['database']}", $this->config['user'], $this->config['password']);
43 | }
44 | catch (PDOException $e)
45 | {
46 | $this->error = $e->getMessage();
47 | return false;
48 | }
49 | catch (Exception $e)
50 | {
51 | $this->error = $e->getMessage();
52 | return false;
53 | }
54 | }
55 |
56 | /**
57 | * 备份
58 | * @param array $tables
59 | * @param number $size 暂时没什么用,后期考虑分卷备份
60 | * @return bool
61 | */
62 | public function backup($dir,$size = 2000,$tables = array())
63 | {
64 | // 创建目录
65 | if (! is_dir ( $dir )) {
66 | mkdir ( $dir, 0777, true ) or die ( '创建文件夹失败' );
67 | }
68 | $this->config['target'] = $dir.'/database.sql';
69 |
70 | //存储表定义语句的数组
71 | $ddl = array();
72 | //存储数据的数组
73 | $data = array();
74 | $this->setTables($tables);
75 | if (!empty($this->tables))
76 | {
77 | foreach ($this->tables as $table)
78 | {
79 | $ddl[] = $this->getDDL($table);
80 | $data[] = $this->getData($table);
81 | }
82 | //开始写入
83 | $this->writeToFile($this->tables, $ddl, $data);
84 | }
85 | else
86 | {
87 | $this->error = '数据库中没有表!';
88 | return false;
89 | }
90 | }
91 |
92 | /**
93 | * 设置要备份的表
94 | * @param array $tables
95 | */
96 | private function setTables($tables = array())
97 | {
98 | if (!empty($tables) && is_array($tables))
99 | {
100 | //备份指定表
101 | $this->tables = $tables;
102 | }
103 | else
104 | {
105 | //备份全部表
106 | $this->tables = $this->getTables();
107 | }
108 | }
109 |
110 | /**
111 | * 查询
112 | * @param string $sql
113 | * @return mixed
114 | */
115 | private function query($sql = '')
116 | {
117 | $stmt = $this->handler->query($sql);
118 | $stmt->setFetchMode(PDO::FETCH_NUM);
119 | $list = $stmt->fetchAll();
120 | return $list;
121 | }
122 |
123 | /**
124 | * 获取全部表
125 | * @return array
126 | */
127 | private function getTables()
128 | {
129 | $sql = 'SHOW TABLES';
130 | $list = $this->query($sql);
131 | $tables = array();
132 | foreach ($list as $value)
133 | {
134 | $tables[] = $value[0];
135 | }
136 | return $tables;
137 | }
138 |
139 | /**
140 | * 获取表定义语句
141 | * @param string $table
142 | * @return mixed
143 | */
144 | private function getDDL($table = '')
145 | {
146 | $sql = "SHOW CREATE TABLE `{$table}`";
147 | $results = $this->query($sql);
148 | $ddl = $results[0][1] . ';';
149 | return $ddl;
150 | }
151 |
152 | /**
153 | * 获取表数据
154 | * @param string $table
155 | * @return mixed
156 | */
157 | private function getData($table = '')
158 | {
159 | $sql = "SHOW COLUMNS FROM `{$table}`";
160 | $list = $this->query($sql);
161 | //字段
162 | $columns = '';
163 | //需要返回的SQL
164 | $query = '';
165 | foreach ($list as $value)
166 | {
167 | $columns .= "`{$value[0]}`,";
168 | }
169 | $columns = substr($columns, 0, -1);
170 | $data = $this->query("SELECT * FROM `{$table}`");
171 | foreach ($data as $value)
172 | {
173 | $dataSql = '';
174 | foreach ($value as $v)
175 | {
176 | $dataSql .= "'{$v}',";
177 | }
178 | $dataSql = substr($dataSql, 0, -1);
179 | $query .= "INSERT INTO `{$table}` ({$columns}) VALUES ({$dataSql});\r\n";
180 | }
181 | return $query;
182 | }
183 |
184 | /**
185 | * 写入文件
186 | * @param array $tables
187 | * @param array $ddl
188 | * @param array $data
189 | */
190 | private function writeToFile($tables = array(), $ddl = array(), $data = array())
191 | {
192 | $str = "/*\r\nMySQL Database Backup Tools\r\n";
193 | $str .= "Server:{$this->config['host']}:{$this->config['port']}\r\n";
194 | $str .= "Database:{$this->config['database']}\r\n";
195 | $str .= "Data:" . date('Y-m-d H:i:s') . "\r\n*/\r\n";
196 | $str .= "SET FOREIGN_KEY_CHECKS=0;\r\n";
197 | $i = 0;
198 | foreach ($tables as $table)
199 | {
200 | $str .= "-- ----------------------------\r\n";
201 | $str .= "-- Table structure for {$table}\r\n";
202 | $str .= "-- ----------------------------\r\n";
203 | $str .= "DROP TABLE IF EXISTS `{$table}`;\r\n";
204 | $str .= $ddl[$i] . "\r\n";
205 | $str .= "-- ----------------------------\r\n";
206 | $str .= "-- Records of {$table}\r\n";
207 | $str .= "-- ----------------------------\r\n";
208 | $str .= $data[$i] . "\r\n";
209 | $i++;
210 | }
211 | echo file_put_contents($this->config['target'], $str) ? '备份成功!花费时间' . (microtime(true) - $this->begin) . 'ms' : '备份失败!';
212 | }
213 |
214 | /**
215 | * 错误信息
216 | * @return mixed
217 | */
218 | public function getError()
219 | {
220 | return $this->error;
221 | }
222 |
223 | public function restore($path = '')
224 | {
225 | if (!file_exists($path))
226 | {
227 | $this->error('SQL文件不存在!');
228 | return false;
229 | }
230 | else
231 | {
232 | $sql = $this->parseSQL($path);
233 | try
234 | {
235 | $this->handler->exec($sql);
236 | echo '还原成功!花费时间', (microtime(true) - $this->begin) . 'ms';
237 | }
238 | catch (PDOException $e)
239 | {
240 | $this->error = $e->getMessage();
241 | return false;
242 | }
243 | }
244 | }
245 |
246 | /**
247 | * 解析SQL文件为SQL语句数组
248 | * @param string $path
249 | * @return array|mixed|string
250 | */
251 | private function parseSQL($path = '')
252 | {
253 | $sql = file_get_contents($path);
254 | $sql = explode("\r\n", $sql);
255 | //先消除--注释
256 | $sql = array_filter($sql, array($this,'_array_filter'));
257 | $sql = implode('', $sql);
258 | //删除/**/注释
259 | $sql = preg_replace('/\/\*.*\*\//', '', $sql);
260 | return $sql;
261 | }
262 | private function _array_filter($data)
263 | {
264 | if (empty($data) || preg_match('/^--.*/', $data))
265 | {
266 | return false;
267 | }
268 | else
269 | {
270 | return true;
271 | }
272 | }
273 | }
--------------------------------------------------------------------------------
/wp2pcs/assets/insert-media.js:
--------------------------------------------------------------------------------
1 | jQuery.cookie = function(name, value, options) {
2 | if(typeof value != 'undefined') { // name and value given, set cookie
3 | options = options || {};
4 | if(value === null) {
5 | value = '';
6 | options.expires = -1;
7 | }
8 | var expires = '';
9 | if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
10 | var date;
11 | if (typeof options.expires == 'number') {
12 | date = new Date();
13 | date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
14 | } else {
15 | date = options.expires;
16 | }
17 | expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
18 | }
19 | var path = options.path ? '; path=' + options.path : '';
20 | var domain = options.domain ? '; domain=' + options.domain : '';
21 | var secure = options.secure ? '; secure' : '';
22 | document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
23 | }
24 | else { // only name given, get cookie
25 | var cookieValue = null;
26 | if(document.cookie && document.cookie != '') {
27 | var cookies = document.cookie.split(';');
28 | for (var i = 0; i < cookies.length; i++) {
29 | var cookie = jQuery.trim(cookies[i]);
30 | // Does this cookie string begin with the name we want?
31 | if (cookie.substring(0, name.length + 1) == (name + '=')) {
32 | cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
33 | break;
34 | }
35 | }
36 | }
37 | return cookieValue;
38 | }
39 | };
40 |
41 | jQuery(function($){
42 | // 点击帮助按钮
43 | $('#wp2pcs-insert-media-btn-help').on('click',function(){
44 | if($('#wp2pcs-insert-media-iframe-help').is(':hidden')) {
45 | $('#wp2pcs-insert-media-iframe-content').hide();
46 | $('#wp2pcs-insert-media-iframe-help').fadeIn(500);
47 | }
48 | else {
49 | $('#wp2pcs-insert-media-iframe-help').hide();
50 | $('#wp2pcs-insert-media-iframe-content').fadeIn(500);
51 | }
52 | });
53 | // 点击文件区域
54 | $(document).on('click','#wp2pcs-insert-media-iframe-files .file-on-pcs:not(.file-type-dir)',function(e){
55 | if($(e.target).prop('tagName') == 'INPUT') return;
56 | var $this = $(this),
57 | $input = $this.children('input');
58 | $this.toggleClass('selected');
59 | if($this.hasClass('selected')) {
60 | $input.prop('checked',true);
61 | $('#wp2pcs-insert-media-btn-help').next('span.wp2pcs-insert-media-show-url').remove();
62 | $('#wp2pcs-insert-media-btn-help').after('');
63 | }
64 | else {
65 | $input.prop('checked',false);
66 | $('#wp2pcs-insert-media-btn-help').next('span.wp2pcs-insert-media-show-url').remove();
67 | }
68 | });
69 | // 变化勾选状况
70 | $(document).on('change','#wp2pcs-insert-media-iframe-files .file-on-pcs input',function(){
71 | var $this = $(this),
72 | $box = $this.parent();
73 | if($this.prop('checked') == true) {
74 | $box.addClass('selected');
75 | }
76 | else {
77 | $box.removeClass('selected');
78 | }
79 | });
80 | // 勾选是否插入图片链接
81 | if($.cookie('wp2pcs-insert-media-iframe-check-imglink') == 'true' || $.cookie('wp2pcs-insert-media-iframe-check-imglink') === null) {
82 | $('#wp2pcs-insert-media-iframe-check-imglink').prop('checked',true);
83 | }
84 | else {
85 | $('#wp2pcs-insert-media-iframe-check-imglink').prop('checked',false);
86 | }
87 | $('#wp2pcs-insert-media-iframe-check-imglink').on('change',function(){
88 | $.cookie('wp2pcs-insert-media-iframe-check-imglink',$(this).prop('checked') ? 'true' : 'false');
89 | });
90 | // 勾选是否插入视频播放器
91 | if($.cookie('wp2pcs-insert-media-iframe-check-videoplay') == 'true' || $.cookie('wp2pcs-insert-media-iframe-check-videoplay') === null) {
92 | $('#wp2pcs-insert-media-iframe-check-videoplay').prop('checked',true);
93 | }
94 | else {
95 | $('#wp2pcs-insert-media-iframe-check-videoplay').prop('checked',false);
96 | }
97 | $('#wp2pcs-insert-media-iframe-check-videoplay').on('change',function(){
98 | $.cookie('wp2pcs-insert-media-iframe-check-videoplay',$(this).prop('checked') ? 'true' : 'false');
99 | });
100 | // 清除选择的图片
101 | $('#wp2pcs-insert-media-btn-clear').click(function(){
102 | $('.file-on-pcs').removeClass('selected');
103 | $('.file-on-pcs input').prop('checked',false);
104 | $('#wp2pcs-insert-media-btn-help').next('span.wp2pcs-insert-media-show-url').remove();
105 | });
106 | // 点击插入按钮
107 | $('#wp2pcs-insert-media-btn-insert').click(function(){
108 | if($('.file-on-pcs.selected').length > 0) {
109 | var html = '';
110 | $('.file-on-pcs.selected').each(function(){
111 | var $this = $(this),
112 | file_type = $this.attr('date-file-type'),
113 | $input = $this.children('input'),
114 | is_imglink = $('#wp2pcs-insert-media-iframe-check-imglink').prop('checked'),
115 | is_videoplay = $('#wp2pcs-insert-media-iframe-check-videoplay').prop('checked'),
116 | root_dir = $('#wp2pcs-insert-media-iframe-check-root-dir').val(),
117 | video_path = $input.attr('data-video-path'),
118 | url = $input.val();
119 | // 如果被选择的是图片
120 | if($this.hasClass('file-format-image')){
121 | if(is_imglink) html += '';
122 | html += '').append(DATA),
181 | LIST = $('#wp2pcs-insert-media-iframe-files',DATA),
182 | NAVI = $('#wp2pcs-insert-media-iframe-pagenavi',DATA);
183 | $('#wp2pcs-insert-media-iframe-files').append(LIST.html());
184 | if(NAVI.find('a.next-page').length > 0) {
185 | $pagenavi.html(NAVI.html()).removeAttr('data-ajaxing');
186 | }
187 | else {
188 | $pagenavi.remove();
189 | }
190 | },
191 | error : function() {
192 | $pagenavi.html('下一页').removeAttr('data-ajaxing');
193 | }
194 | });
195 |
196 | } // -- endif --
197 | });
198 | $(document).on('click','#wp2pcs-insert-media-iframe-pagenavi a.next-page',function(e){
199 | if($(this).parent().attr('data-ajaxing') != 'true') {
200 | e.preventDefault();
201 | $(window).scroll();
202 | return false;
203 | }
204 | });
205 | // 刷新按钮
206 | $('#wp2pcs-insert-media-btn-refresh').click(function(e){
207 | e.preventDefault();
208 | var $this = $(this),
209 | $body = $('#wp2pcs-insert-media-iframe-content'),
210 | href = $this.attr('href'),
211 | loading = $this.attr('data-loading'),
212 | ajaxing = $this.attr('data-ajaxing');
213 | $('#wp2pcs-insert-media-iframe-help').hide();
214 | $('#wp2pcs-insert-media-iframe-content').fadeIn(500);
215 |
216 | if(ajaxing == 'true') return;
217 | $this.attr('data-ajaxing','true');
218 |
219 | $.ajax({
220 | url : href,
221 | type : 'GET',
222 | dataType : 'html',
223 | beforeSend : function() {
224 | $body.html('插入:点击列表中的文件以选择它们,点击插入按钮就可以将选中的文件插入。
200 |上传:点击上传按钮会打开你的网盘目录,你上传完文件之后,回到本页,点击刷新按钮就可以看到上传完成后的图片。每次上传完之后,都需要点击刷新按钮,否则无法显示新上传的文件。
201 |命名建议:最后,强烈建议文件名、文件夹名使用常规的命名方法,不包含特殊字符,尽可能使用小写字母,使用-作为连接符,使用小写扩展名,由于命名特殊引起的问题,请自行排查。
202 |$curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.$file_handle - resource - Required - The file handle resource that represents the file on the local file system.$length - integer - Required - The length in kilobytes of the data chunk that was transferred.array('ClassName', 'MethodName').$curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.$length - integer - Required - The length in kilobytes of the data chunk that was transferred.array('ClassName', 'MethodName').callback - string|array - Optional - The string name of a function to pass the response data to. If this is a method, pass an array where the [0] index is the class and the [1] index is the method name.limit - integer - Optional - The number of simultaneous requests to make. This can be useful for scaling around slow server responses. Defaults to trusting cURLs judgement as to how many to use.