├── 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 ''; 25 | echo 'WP2PCS'; 26 | echo ''; 27 | echo ''; 28 | echo ''; 29 | echo ''; 30 | echo ''; 31 | exit; 32 | } 33 | // 第二步,当向百度请求成功之后,回到本页,获得一个code,根据这个code获得我想要的信息,并把这些信息保存到数据库,同时返回给用户的网站 34 | elseif($code) { 35 | $access_token = $baidu->getAccessToken();// 进行一道加密处理 36 | $refresh_token = $baidu->getRefreshToken(); 37 | $url = $_SESSION['url']; 38 | if(strpos($url,'?') === false) { 39 | $url .= '?'; 40 | } 41 | else { 42 | $url .= '&'; 43 | } 44 | $url .= "action=update_token&access_token=$access_token&refresh_token=$refresh_token&oauth=baidupcs"; 45 | session_unset(); 46 | session_destroy(); 47 | header('Location:'.$url); 48 | } 49 | else { 50 | echo 'No thing.'; 51 | } 52 | -------------------------------------------------------------------------------- /wp2pcs/admin/about.php: -------------------------------------------------------------------------------- 1 | 8 | 9 | 30 | 31 |
32 | 38 |
39 |

版本,极简!

40 | 43 | 54 |
55 |

WP2PCS官网不再提供服务,如果在插件使用过程中有什么问题,可以进入GitHub提交issue。

56 |

如果你不喜欢这个版本,上一个稳定版可以在这里下载。

57 |
58 |
59 |
60 |
61 | -------------------------------------------------------------------------------- /wp2pcs/admin/general.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | 8 | 9 |
10 |
11 |

12 |

授权信息

13 |
14 | 主机对cURL模块支持不完整,请联系主机商咨询。

'; 17 | } 18 | elseif(!WP2PCS_BAIDU_ACCESS_TOKEN) { 19 | $baidupcs_btn_class = 'button-primary'; 20 | } 21 | else { 22 | $baidupcs_btn_class = 'button'; 23 | global $BaiduPCS; 24 | $quota = json_decode($BaiduPCS->getQuota()); 25 | if(isset($quota->error_code) && in_array($quota->error_code,array(100,110,111,31023))) { 26 | echo '

百度账号授权信息可能已经过期,点击下方按钮更新授权试试。

'; 27 | $baidupcs_btn_class = 'button-primary'; 28 | } 29 | elseif(isset($quota->error_code)){ 30 | echo '

获取百度网盘信息错误,'.$quota->error_code.':'.$quota->error_msg.'。

'; 31 | $baidupcs_btn_class = 'button-primary'; 32 | } 33 | elseif((int)$quota->quota == 0) { 34 | echo '

获取百度网盘信息错误。可能是因为你的主机不支持curl,不建议使用。

'; 35 | $baidupcs_btn_class = 'button-primary'; 36 | } 37 | else{ 38 | echo '

当前百度网盘总'.number_format(($quota->quota/(1024*1024)),2).'MB,剩余'.number_format((($quota->quota - $quota->used)/(1024*1024)),2).'MB。授权成功后请尽量不要切换账号授权,不同网盘之间切换会导致附件失效。

'; 39 | echo '

ACCESS TOKEN: '.WP2PCS_BAIDU_ACCESS_TOKEN.'

'; 40 | echo '

REFRESH TOKEN: '.WP2PCS_BAIDU_REFRESH_TOKEN.'

'; 41 | } 42 | } 43 | ?> 44 |

45 | 百度授权 46 |

47 |
48 |
49 | 50 |
51 |

52 |

简要说明

53 |
54 |

WP2PCS当前版本:

55 |

PHP版本:(注:PHP必须支持PDO方式操作MySQL)

56 |

交流QQ群:292172954

57 |

作者:@否子戈,点击这里获得支持

58 |

向作者捐赠:支付宝476206120@qq.com,财付通476206120,只有你的支持,才能维持WP2PCS继续正常使用。

59 |
60 |
61 |
62 | 63 |
64 | -------------------------------------------------------------------------------- /wp2pcs/assets/insert-media.css: -------------------------------------------------------------------------------- 1 | html,body { 2 | background-color: #fff; 3 | margin: 10px; 4 | } 5 | body { 6 | padding-top: 40px; 7 | } 8 | .body-bottom { 9 | height: 80px; 10 | } 11 | .clear { 12 | clear: both; 13 | } 14 | 15 | #wp2pcs-insert-media-iframe-buttons { 16 | position: fixed; 17 | left: 0; 18 | bottom: 0; 19 | height: 30px; 20 | padding: 10px; 21 | border-top: 1px solid #dedede; 22 | width: 100%; 23 | text-align: right; 24 | z-index: 9999; 25 | background-color: #fff; 26 | } 27 | #wp2pcs-insert-media-iframe-buttons .button { 28 | margin-right: 5px; 29 | } 30 | #wp2pcs-insert-media-iframe-buttons #wp2pcs-insert-media-btn-insert { 31 | margin-right: 30px; 32 | } 33 | #wp2pcs-insert-media-iframe-buttons .float-left { 34 | float: left; 35 | } 36 | 37 | #wp2pcs-insert-media-iframe-topbar { 38 | position: fixed; 39 | left: 0; 40 | top: 0; 41 | height: 30px; 42 | line-height: 30px; 43 | padding-left: 10px; 44 | border-bottom: 1px solid #dedede; 45 | width: 100%; 46 | z-index: 9999; 47 | background-color: #fff; 48 | } 49 | #wp2pcs-insert-media-iframe-place { 50 | float: left; 51 | } 52 | #wp2pcs-insert-media-iframe-check { 53 | float: right; 54 | margin-right: 30px; 55 | } 56 | 57 | 58 | .file-on-pcs { 59 | width: 150px; 60 | height: 150px; 61 | line-height: 150px; 62 | overflow: hidden; 63 | float: left; 64 | margin: 5px; 65 | border: #dedede solid 5px; 66 | position: relative; 67 | text-align: center; 68 | background-color: #f9f9f9; 69 | background-image: url(file-bg.png); 70 | background-repeat: no-repeat; 71 | background-position: center; 72 | } 73 | .file-on-pcs.file-type-dir { 74 | background-color: #FFC125; 75 | background-image: url(dir-bg.png); 76 | } 77 | .file-on-pcs.file-format-image { 78 | background-image: url(image-bg.png); 79 | } 80 | .file-on-pcs.file-format-music { 81 | background-image: url(music-bg.png); 82 | } 83 | .file-on-pcs.file-format-video { 84 | background-image: url(video-bg.png); 85 | } 86 | .file-on-pcs:hover, 87 | .file-on-pcs.selected { 88 | border: #1E8CBE solid 5px; 89 | } 90 | .file-on-pcs a { 91 | display: block; 92 | width: 100%; 93 | height: 100%; 94 | text-decoration: none; 95 | font-size: 1.2em; 96 | font-weight: bold; 97 | color: #fff; 98 | text-shadow: 0px 0px 2px #999; 99 | } 100 | .file-on-pcs input { 101 | position: absolute; 102 | top: 5px; 103 | left: 5px; 104 | } 105 | .file-on-pcs img { 106 | width: 100%; 107 | height: 100%; 108 | } 109 | 110 | #wp2pcs-insert-media-iframe-help { 111 | display: none; 112 | } 113 | #wp2pcs-insert-media-iframe-upload { 114 | position: fixed; 115 | left: 0; 116 | bottom: 50px; 117 | display: none; 118 | width: 100%; 119 | height: 100%; 120 | overflow-y: hidden; 121 | background: url(loading.gif) no-repeat center; 122 | } 123 | #wp2pcs-insert-media-iframe-upload iframe { 124 | width: 1100px; 125 | height: 95%; 126 | margin: 25px 0 0 -215px; 127 | } 128 | 129 | #wp2pcs-insert-media-iframe-pagenavi { 130 | padding-top: 20px; 131 | text-align: center; 132 | font-size: 1.2em; 133 | } 134 | #wp2pcs-insert-media-iframe-pagenavi a { 135 | margin: 0 .5em; 136 | } 137 | #wp2pcs-insert-media-iframe-pagenavi img { 138 | margin-top: 40px; 139 | } -------------------------------------------------------------------------------- /wp2pcs/admin/backup.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | 8 | 9 |
10 |
11 | 12 | 13 |

提示:还没有百度授权。

14 | 15 | 16 |
17 |

18 |

定时开关

19 |
20 |

21 | 28 | 文件: 35 | 数据: 42 | 时间: 47 |

48 |

所有备份文件将被保存在百度云盘的/backup路径中

49 | 下次运行备份时间:'.date('Y-m-d H:i:s',$backup_timestamp).'

'; ?> 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 |
-------------------------------------------------------------------------------- /wp2pcs/hook/load.php: -------------------------------------------------------------------------------- 1 | error_code) && in_array($meta->error_code,array(100,110,111,31023))) { 46 | $refresh_token = get_option('wp2pcs_baidupcs_refresh_token'); 47 | $data = wp2pcs_curl(WP2PCS_API_URL.'/client-baidu-refresh-token.php',array('refresh_token' => $refresh_token)); 48 | $data = json_decode($data); 49 | if(isset($data->access_token) && isset($data->refresh_token)) { 50 | update_option('wp2pcs_baidupcs_access_token',$data->access_token); 51 | update_option('wp2pcs_baidupcs_refresh_token',$data->refresh_token); 52 | update_option('wp2pcs_baidu_token_update_time',time()); 53 | $access_token = $data->access_token; 54 | // 用新的token获取文件信息 55 | $meta = wp2pcs_curl("https://pcs.baidu.com/rest/2.0/pcs/file?method=meta&access_token=$access_token&path=".rawurlencode($path)); 56 | $meta = json_decode($meta); 57 | } 58 | else { 59 | do_action('wp2pcs_load_file_error',$path,$meta); 60 | wp_die($meta->error_code.': '.$meta->error_msg); 61 | } 62 | } 63 | // 如果文件不存在,就试图从共享目录中抓取文件 64 | if(isset($meta->error_code) && $meta->error_code == 31066) { 65 | $path = str_replace(WP2PCS_BAIDUPCS_REMOTE_ROOT.'/load',WP2PCS_BAIDUPCS_SHARE_ROOT,$path); 66 | $meta = wp2pcs_curl("https://pcs.baidu.com/rest/2.0/pcs/file?method=meta&access_token=$access_token&path=".rawurlencode($path)); 67 | $meta = json_decode($meta); 68 | } 69 | // 如果抓取错误 70 | if(isset($meta->error_msg)){ 71 | do_action('wp2pcs_load_file_error',$path,$meta); 72 | wp_die($meta->error_code.': '.$meta->error_msg); 73 | } 74 | 75 | do_action('wp2pcs_load_file_before',$path,$meta); 76 | 77 | // 开始抓取 78 | $src = "https://pcs.baidu.com/rest/2.0/pcs/stream?method=download&access_token=$access_token&path=".rawurlencode($path); 79 | $result = wp2pcs_curl($src); 80 | // 如果抓取错误 81 | $check = json_decode($result); 82 | if(isset($check->error_msg)) { 83 | wp_die('ERROR: '.$check->error_code.'. '.$check->error_msg); 84 | } 85 | 86 | header('Content-type: image/jpeg'); 87 | 88 | ob_clean(); 89 | flush(); 90 | echo $result; 91 | 92 | do_action('wp2pcs_load_file_after',$path,$meta,$result,null,null); 93 | exit(); -------------------------------------------------------------------------------- /wp2pcs/assets/manage-media.css: -------------------------------------------------------------------------------- 1 | #wpcontent { 2 | background: #fff !important; 3 | height: 100% !important; 4 | } 5 | .update-nag { 6 | display: none !important; 7 | } 8 | #wp2pcs-manage-media-page { 9 | } 10 | #wp2pcs-manage-media-page-top-bar { 11 | border: 1px solid #dedede; 12 | background: #fff; 13 | width: 95%; 14 | margin: 10px 5px; 15 | z-index: 9; 16 | text-align: left; 17 | border: #dedede solid 5px; 18 | } 19 | #wp2pcs-manage-media-page-btns { 20 | float: right; 21 | margin: 10px; 22 | } 23 | #wp2pcs-manage-media-page-place { 24 | float: left; 25 | margin: 10px; 26 | } 27 | #wp2pcs-manage-media-page-file-info { 28 | clear: both; 29 | margin: 10px; 30 | padding-left: 70px; 31 | position: relative; 32 | display: none; 33 | } 34 | #wp2pcs-manage-media-page-file-info .close { 35 | position: absolute; 36 | right: 10px; 37 | top: 5px; 38 | font-size: 1.4em; 39 | text-decoration: none; 40 | } 41 | #wp2pcs-manage-media-page-file-info .thumb { 42 | position: absolute; 43 | left: 0; 44 | top: 0; 45 | max-width: 60px; 46 | max-height: 60px; 47 | overflow: hidden; 48 | } 49 | #wp2pcs-manage-media-page-file-info .thumb img { 50 | max-width: 100%; 51 | } 52 | #wp2pcs-manage-media-page-file-info .format, 53 | #wp2pcs-manage-media-page-file-info .name, 54 | #wp2pcs-manage-media-page-file-info .size { 55 | display: inline; 56 | margin-right: 5px; 57 | } 58 | #wp2pcs-manage-media-page-file-info .name { 59 | font-weight: bold; 60 | } 61 | #wp2pcs-manage-media-page-file-info .code { 62 | background: #f1f1f1; 63 | padding: 5px; 64 | margin-top: 5px; 65 | white-space:nowrap; 66 | word-break : keep-all; 67 | width: 95%; 68 | resize: none; 69 | } 70 | 71 | .file-on-pcs { 72 | width: 150px; 73 | height: 150px; 74 | line-height: 150px; 75 | overflow: hidden; 76 | float: left; 77 | margin: 5px; 78 | border: #dedede solid 5px; 79 | position: relative; 80 | text-align: center; 81 | background-color: #f9f9f9; 82 | background-image: url(file-bg.png); 83 | background-repeat: no-repeat; 84 | background-position: center; 85 | } 86 | .file-on-pcs.file-type-dir { 87 | background-color: #FFC125; 88 | background-image: url(dir-bg.png); 89 | } 90 | .file-on-pcs.file-format-image { 91 | background-image: url(image-bg.png); 92 | } 93 | .file-on-pcs.file-format-music { 94 | background-image: url(music-bg.png); 95 | } 96 | .file-on-pcs.file-format-video { 97 | background-image: url(video-bg.png); 98 | } 99 | .file-on-pcs:hover, 100 | .file-on-pcs.selected { 101 | border: #1E8CBE solid 5px; 102 | } 103 | .file-on-pcs a { 104 | display: block; 105 | width: 100%; 106 | height: 100%; 107 | text-decoration: none; 108 | font-size: 1.2em; 109 | font-weight: bold; 110 | color: #fff; 111 | text-shadow: 0px 0px 2px #999; 112 | } 113 | .file-on-pcs input { 114 | position: absolute; 115 | top: 5px; 116 | left: 5px; 117 | } 118 | .file-on-pcs img { 119 | width: 100%; 120 | height: 100%; 121 | } 122 | 123 | #wp2pcs-manage-media-page-upload { 124 | display: none; 125 | width: 900px; 126 | height: 500px; 127 | margin-left: 10px; 128 | margin-top: 60px; 129 | overflow-y: hidden; 130 | background: url(loading.gif) no-repeat center; 131 | } 132 | #wp2pcs-manage-media-page-upload iframe { 133 | width: 1100px; 134 | height: 550px; 135 | margin: -50px 0 0 -215px; 136 | } 137 | 138 | #wp2pcs-manage-media-page-pagenavi { 139 | padding-top: 20px; 140 | text-align: center; 141 | font-size: 1.2em; 142 | } 143 | #wp2pcs-manage-media-page-pagenavi a { 144 | margin: 0 .5em; 145 | } 146 | #wp2pcs-insert-media-iframe-pagenavi img { 147 | margin-top: 40px; 148 | } -------------------------------------------------------------------------------- /wp2pcs/libs/functions.backup.php: -------------------------------------------------------------------------------- 1 | upload($file_content,$remote_file,''); 20 | return; 21 | } 22 | // 开始分片上传 23 | $handle = @fopen($local_file,'rb'); 24 | while(!@feof($handle)){ 25 | $file_block_content = fread($handle,$file_block_size); 26 | $block = $BaiduPCS->upload($file_block_content,$remote_file,'',false,true); 27 | if(!is_array($block)){ 28 | $block = json_decode($block,true); 29 | } 30 | if(isset($block['md5'])){ 31 | array_push($file_blocks,$block['md5']); 32 | } 33 | } 34 | fclose($handle); 35 | if(count($file_blocks) > 1){ 36 | $BaiduPCS->createSuperFile($remote_file,'',$file_blocks,''); 37 | } 38 | } 39 | 40 | // 执行备份 41 | function wp2pcs_backup_process($backup_file = true,$backup_data = true) { 42 | if(!$backup_file && !$backup_data) return null; 43 | 44 | $DBZIP = new DatabaseTool(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME); 45 | $FileZIP = new FileZIP; 46 | $zip_file_name = date('Y.m.d-H.i.s').'-'.(int)$backup_file.(int)$backup_data.wp2pcs_rand(8).'.zip'; 47 | $zip_file_path = WP2PCS_TEMP_DIR.DIRECTORY_SEPARATOR.$zip_file_name; 48 | $zip_data_path = WP2PCS_TEMP_DIR.DIRECTORY_SEPARATOR.'database-backup'; 49 | $webroot_path = realpath(ABSPATH.'/../'); 50 | wp2pcs_rmdir(WP2PCS_TEMP_DIR,false);// 清空临时目录 51 | // 备份文件并生成 52 | if($FileZIP->startfile($zip_file_path)) { 53 | // 备份数据 54 | if($backup_data) { 55 | $DBZIP->backup($zip_data_path,2000); 56 | $FileZIP->process($zip_data_path,WP2PCS_TEMP_DIR); 57 | wp2pcs_rmdir($zip_data_path); 58 | } 59 | // 备份文件 60 | if($backup_file) { 61 | $path_include = stripslashes(get_option('wp2pcs_backup_path_include')); 62 | $path_exclude = stripslashes(get_option('wp2pcs_backup_path_exclude')); 63 | $path_must = stripslashes(get_option('wp2pcs_backup_path_must')); 64 | // 白名单 65 | if($path_must) { 66 | $path_must = array_filter(explode("\r\n",$path_must)); 67 | foreach($path_must as $path) { 68 | if($path) $FileZIP->include_path($path); 69 | } 70 | } 71 | // 排除黑名单 72 | if($path_exclude) { 73 | $path_exclude = array_filter(explode("\r\n",$path_exclude)); 74 | foreach($path_exclude as $path) { 75 | if($path) $FileZIP->exclude_path($path); 76 | } 77 | } 78 | $FileZIP->exclude_path(WP2PCS_TEMP_DIR); 79 | // 按照给定的路径进行打包 80 | if($path_include) { 81 | $path_include = array_filter(explode("\r\n",$path_include)); 82 | foreach($path_include as $path) { 83 | $FileZIP->process($path,$webroot_path); 84 | } 85 | } 86 | else { 87 | $FileZIP->process(realpath(ABSPATH),$webroot_path); 88 | } 89 | } 90 | 91 | $FileZIP->createfile(); 92 | return $zip_file_path; 93 | } 94 | else { 95 | return null; 96 | } 97 | } 98 | 99 | function wp2pcs_backup_to_baidupcs($backup_file = true,$backup_data = true) { 100 | $zip_file = wp2pcs_backup_process($backup_file,$backup_data); 101 | $file_name = basename($zip_file); 102 | wp2pcs_upload_to_baidupcs($zip_file,'/backup/'.$file_name); 103 | wp2pcs_rmdir(WP2PCS_TEMP_DIR,false);// 清空临时目录 104 | } 105 | 106 | function wp2pcs_reccurences(){ 107 | return array( 108 | 'never' => array('interval' => 0, 'display' => '永不备份'), 109 | 'daily' => array('interval' => 3600*24, 'display' => '每天一次'), 110 | 'weekly' => array('interval' => 3600*24*7, 'display' => '每周一次'), 111 | 'monthly' => array('interval' => 3600*24*30, 'display' => '每月一次') 112 | ); 113 | } -------------------------------------------------------------------------------- /wp2pcs/admin/load.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | 8 | 9 |
10 |
11 | 12 | 13 |

提示:还没有百度授权。

14 | 15 | 16 | 17 |
18 |

19 |

资源调用开关

20 |
21 |

22 | 26 | 资源调用功能 27 |

28 |

如果你只希望使用备份功能,可以关闭资源调用功能,这样可以节省一些资源。但是关闭之后,将无法显示你之前插入的百度云图片。
资源调用会先从百度云抓取资源到你的服务器,然后才显示给用户看,所以要消耗两边的流量。
默认设置了一个月的本地浏览器缓存时间,你可以在config.php中修改。

29 |
30 |
31 | 32 |
33 |

34 |

云端路径

35 |
36 |

站点目录:/load

37 |

共享目录:

38 |
39 |
40 | 41 | 45 |
46 |

47 |

链接形式

48 |
49 |

50 | 54 |

55 |

56 | 61 |

62 |

63 | 67 |

68 |
69 |
70 | 71 | 75 |
76 |

77 |

媒体插入

78 |
79 |

插入图片时插入其链接?

83 |
84 |
85 |

插入面板默认目录:

89 |
90 |
91 | 92 | 93 | 94 | 95 | 96 |
97 |
98 | 99 |
100 | -------------------------------------------------------------------------------- /wp2pcs/libs/functions.php: -------------------------------------------------------------------------------- 1 | time()) { 52 | header("Expires: ".gmdate("D, d M Y H:i:s",$expire)." GMT"); 53 | header("Last-Modified: $last_modified",true,304); 54 | exit; 55 | } 56 | } 57 | // 如果不存在缓存,则增加上次更新时间,从而加入缓存 58 | header("Expires: ".gmdate("D, d M Y H:i:s",strtotime($expire))." GMT"); 59 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 60 | } 61 | 62 | // 判断cache是否存在 63 | function wp2pcs_has_cache($path) { 64 | $path = str_replace(WP2PCS_BAIDUPCS_REMOTE_ROOT,'',$path); 65 | if(!file_exists(WP2PCS_CACHE_DIR.DIRECTORY_SEPARATOR.$path)) {// 该缓存文件不存在 66 | return false; 67 | } 68 | return true; 69 | } 70 | // 获取cache 71 | function wp2pcs_get_cache($path) { 72 | $path = str_replace(WP2PCS_BAIDUPCS_REMOTE_ROOT,'',$path); 73 | $cache_file = realpath(WP2PCS_CACHE_DIR.DIRECTORY_SEPARATOR.$path); 74 | if(!$cache_file) {// 该缓存文件不存在 75 | return null; 76 | } 77 | $handle = fopen($cache_file,'rb'); 78 | $content = ''; 79 | while(!feof($handle)){ 80 | $content .= fread($handle, 1024*8); 81 | } 82 | fclose($handle); 83 | return $content; 84 | } 85 | 86 | // 添加cache 87 | function wp2pcs_set_cache($path,$content) { 88 | $path = str_replace(WP2PCS_BAIDUPCS_REMOTE_ROOT,'',$path); 89 | $path = str_replace('/apps/wp2pcs','',$path); 90 | $cache_file = WP2PCS_CACHE_DIR.'/'.$path; 91 | if(DIRECTORY_SEPARATOR == '\\') { 92 | $cache_file = str_replace('/','\\',$cache_file); 93 | $cache_file = str_replace('\\\\','\\',$cache_file); 94 | } 95 | else { 96 | $cache_file = str_replace('//','/',$cache_file); 97 | } 98 | // 创建目录层级 99 | $pathdir = array(); 100 | $pathdir[] = $dir = dirname($cache_file); 101 | while($dir && $dir != '/' && $dir != DIRECTORY_SEPARATOR && $dir != '.' && strpos(realpath(ABSPATH),$dir) === false) { 102 | $pathdir[] = $dir = dirname($dir); 103 | } 104 | @end($pathdir); 105 | do{ 106 | $dir = @current($pathdir); 107 | if(!file_exists($dir)) @mkdir($dir); 108 | } while(@prev($pathdir)); 109 | // 写入文件 110 | $handle = fopen($cache_file,'wb'); 111 | fwrite($handle,$content); 112 | fclose($handle); 113 | return $path; 114 | } 115 | 116 | // 删除一个缓存 117 | function wp2pcs_delete_cache($path) { 118 | $path = str_replace(WP2PCS_BAIDUPCS_REMOTE_ROOT,'',$path); 119 | $cache_file = realpath(WP2PCS_CACHE_DIR.DIRECTORY_SEPARATOR.$path); 120 | if(!$cache_file) { 121 | return false; 122 | } 123 | unlink($cache_file); 124 | return true; 125 | } 126 | 127 | // 清空缓存 128 | function wp2pcs_clean_cache($dir = WP2PCS_CACHE_DIR) { 129 | $dir = realpath($dir); 130 | $handle = opendir($dir); 131 | while($file = readdir($handle)) { 132 | if($file == '.' || $file == '..')continue; 133 | if(is_dir($dir.DIRECTORY_SEPARATOR.$file)) { 134 | wp2pcs_clean_cache($dir.DIRECTORY_SEPARATOR.$file); 135 | } 136 | else { 137 | unlink($dir.DIRECTORY_SEPARATOR.$file); 138 | } 139 | } 140 | closedir($handle); 141 | return true; 142 | } 143 | 144 | // 使用curl抓取 145 | function wp2pcs_curl($url,$post = false,$ssl = true,$referer = false,$headers = null){ 146 | $ch = curl_init(); 147 | curl_setopt($ch,CURLOPT_URL,$url); 148 | curl_setopt($ch, CURLOPT_HEADER, 0); 149 | //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);//安全模式下无法使用 150 | if($referer) { 151 | curl_setopt ($ch,CURLOPT_REFERER,$referer); 152 | } 153 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 154 | if($ssl) { 155 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 156 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 157 | } 158 | if($post){ 159 | curl_setopt($ch, CURLOPT_POST, 1); 160 | curl_setopt($ch, CURLOPT_POSTFIELDS,$post); 161 | } 162 | $result = curl_exec($ch); 163 | curl_close($ch); 164 | return $result; 165 | } 166 | 167 | // 获取当前访问的URL的文件名 168 | function wp2pcs_get_url_file_name() { 169 | $file_name = substr($_SERVER['PHP_SELF'],strrpos($_SERVER['PHP_SELF'],'/')+1); 170 | return $file_name; 171 | } 172 | 173 | // 随机字符串算法 174 | function wp2pcs_rand($length) { 175 | $str = null; 176 | $strPol = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 177 | $max = strlen($strPol)-1; 178 | 179 | for($i=0;$i<$length;$i++) { 180 | $str .= $strPol[mt_rand(0,$max)]; 181 | } 182 | 183 | return $str; 184 | } -------------------------------------------------------------------------------- /oauth-server/BaiduLibs/BaiduOAuth2.php: -------------------------------------------------------------------------------- 1 | 'https://openapi.baidu.com/oauth/2.0/authorize', 25 | 'token' => 'https://openapi.baidu.com/oauth/2.0/token', 26 | 'logout' => 'https://openapi.baidu.com/connect/2.0/logout', 27 | ); 28 | 29 | protected $clientId; 30 | protected $clientSecret; 31 | protected $redirectUri; 32 | 33 | /** 34 | * Constructor 35 | * 36 | * @param string $clientId Client_id of the baidu thirdparty app or access_key of the developer. 37 | * @param string $clientSecret Client_secret of the baidu thirdparty app or secret_key of the developer. 38 | */ 39 | public function __construct($clientId, $clientSecret) 40 | { 41 | $this->clientId = $clientId; 42 | $this->clientSecret = $clientSecret; 43 | } 44 | 45 | /** 46 | * Set the redirect uri for the app. 47 | * 48 | * @param $redirectUri Where to redirect after user authorization. 49 | * @return BaiduOAuth2 50 | */ 51 | public function setRedirectUri($redirectUri) 52 | { 53 | if (empty($redirectUri)) { 54 | $redirectUri = BaiduUtils::getCurrentUrl(); 55 | } 56 | $this->redirectUri = $redirectUri; 57 | return $this; 58 | } 59 | 60 | /** 61 | * Get the redirect uri for the app. 62 | * 63 | * @return string 64 | */ 65 | public function getRedirectUri() 66 | { 67 | return $this->redirectUri; 68 | } 69 | 70 | /** 71 | * Get a Logout URL suitable for use with redirects. 72 | * 73 | * @param string $accessToken Access token for current user 74 | * @param string $next Url to go to after a successful logout 75 | * @return String The URL for the logout flow 76 | */ 77 | public function getLogoutUrl($accessToken, $next = '') 78 | { 79 | $params = array('access_token' => $accessToken, 80 | 'next' => $next ? $next : BaiduUtils::getCurrentUrl()); 81 | return self::$BD_OAUTH2_ENDPOINTS['logout'] . '?' . http_build_query($params, '', '&'); 82 | } 83 | 84 | /** 85 | * Get baidu oauth2's authorization granting url. 86 | * 87 | * @param string $responseType Response type, 'code' or 'token' 88 | * @param string $scope blank space separated list of requested extended perms 89 | * @param string $display Authorization page style, 'page', 'popup', 'touch' or 'mobile' 90 | * @param string $state state parameter 91 | * @return string Page url for authorization granting 92 | */ 93 | public function getAuthorizeUrl($responseType = 'code', $scope = '', $state = '', $display = 'popup') 94 | { 95 | $params = array( 96 | 'client_id' => $this->clientId, 97 | 'response_type' => $responseType, 98 | 'redirect_uri' => $this->redirectUri, 99 | 'scope' => $scope, 100 | 'state' => $state, 101 | 'display' => $display, 102 | ); 103 | return self::$BD_OAUTH2_ENDPOINTS['authorize'] . '?' . http_build_query($params, '', '&'); 104 | } 105 | 106 | /** 107 | * Get access token ifno by authorization code. 108 | * 109 | * @param string $code Authorization code 110 | * @return array|false returns access token info if success, or false if failed 111 | */ 112 | public function getAccessTokenByAuthorizationCode($code) 113 | { 114 | $params = array( 115 | 'grant_type' => 'authorization_code', 116 | 'code' => $code, 117 | 'client_id' => $this->clientId, 118 | 'client_secret' => $this->clientSecret, 119 | 'redirect_uri' => $this->redirectUri, 120 | ); 121 | return $this->makeAccessTokenRequest($params); 122 | } 123 | 124 | /** 125 | * Get access token info by client credentials. 126 | * 127 | * @param string $scope Extend permissions delimited by blank space 128 | * @return array|false returns access token info if success, or false if failed. 129 | */ 130 | public function getAccessTokenByClientCredentials($scope = '') 131 | { 132 | $params = array( 133 | 'grant_type' => 'client_credentials', 134 | 'client_id' => $this->clientId, 135 | 'client_secret' => $this->clientSecret, 136 | 'scope' => $scope, 137 | ); 138 | return $this->makeAccessTokenRequest($params); 139 | } 140 | 141 | /** 142 | * Get access token info by developer credentials 143 | * @param string $accessKey Access key you got from baidu cloud platform 144 | * @param string $secretKey Secret key you got from baidu cloud platform 145 | * @return array|false Returns access token info if success, or false if failed 146 | */ 147 | public function getAccessTokenByDeveloperCredentials($accessKey, $secretKey) 148 | { 149 | $params = array( 150 | 'grant_type' => 'developer_credentials', 151 | 'client_id' => $accessKey, 152 | 'client_secret' => $secretKey, 153 | ); 154 | return $this->makeAccessTokenRequest($params); 155 | } 156 | 157 | /** 158 | * Refresh access token by refresh token. 159 | * 160 | * @param string $refreshToken The refresh token 161 | * @param string $scope Extend permissions delimited by blank space 162 | * @return array|false returns access token info if success, or false if failed. 163 | */ 164 | public function getAccessTokenByRefreshToken($refreshToken, $scope = '') 165 | { 166 | $params = array( 167 | 'grant_type' => 'refresh_token', 168 | 'refresh_token' => $refreshToken, 169 | 'client_id' => $this->clientId, 170 | 'client_secret' => $this->clientSecret, 171 | 'scope' => $scope, 172 | ); 173 | return $this->makeAccessTokenRequest($params); 174 | } 175 | 176 | /** 177 | * Make an oauth access token request 178 | * 179 | * The parameters: 180 | * - client_id: The client identifier, just use api key 181 | * - response_type: 'token' or 'code' 182 | * - redirect_uri: the url to go to after a successful login 183 | * - scope: The scope of the access request expressed as a list of space-delimited, case sensitive strings. 184 | * - state: An opaque value used by the client to maintain state between the request and callback. 185 | * - display: login page style, 'page', 'popup', 'touch' or 'mobile' 186 | * 187 | * @param array $params oauth request parameters 188 | * @return mixed returns access token info if success, or false if failed 189 | */ 190 | public function makeAccessTokenRequest($params) 191 | { 192 | $result = BaiduUtils::request(self::$BD_OAUTH2_ENDPOINTS['token'], $params, 'POST'); 193 | if ($result) { 194 | $result = json_decode($result, true); 195 | if (isset($result['error_description'])) { 196 | BaiduUtils::setError($result['error'], $result['error_description']); 197 | return false; 198 | } 199 | return $result; 200 | } 201 | 202 | return false; 203 | } 204 | } 205 | 206 | 207 | /* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */ -------------------------------------------------------------------------------- /oauth-server/BaiduLibs/BaiduStore.php: -------------------------------------------------------------------------------- 1 | clientId = $clientId; 34 | } 35 | 36 | /** 37 | * Get the variable value specified by the variable key name for 38 | * current session user from the storage system. 39 | * 40 | * @param string $key Variable key name 41 | * @param mix $default Default value if the key couldn't be found 42 | * @return mix Returns the value for the specified key if it exists, 43 | * otherwise return $default value 44 | */ 45 | abstract public function get($key, $default = false); 46 | 47 | /** 48 | * Save the variable item specified by the variable key name into 49 | * the storage system for current session user. 50 | * 51 | * @param string $key Variable key name 52 | * @param mix $value Variable value 53 | * @return bool Returns true if the saving operation is success, 54 | * otherwise returns false 55 | */ 56 | abstract public function set($key, $value); 57 | 58 | /** 59 | * Remove the stored variable item specified by the variable key name 60 | * from the storage system for current session user. 61 | * 62 | * @param string $key Variable key name 63 | * @return bool Returns true if remove success, otherwise returns false 64 | */ 65 | abstract public function remove($key); 66 | 67 | /** 68 | * Remove all the stored variable items for current session user from 69 | * the storage system. 70 | * 71 | * @return bool Returns true if remove success, otherwise returns false 72 | */ 73 | abstract public function removeAll(); 74 | 75 | /** 76 | * Get the actual key name for current storage engine. 77 | * 78 | * @param string $key The original key name 79 | * @return string 80 | */ 81 | protected function getKeyForStore($key) 82 | { 83 | return implode('_', array('bds', $this->clientId, $key)); 84 | } 85 | } 86 | 87 | /** 88 | * Storage engine using Browser Cookie. 89 | */ 90 | class BaiduCookieStore extends BaiduStore 91 | { 92 | /** 93 | * The domain where to save the session cookie. 94 | * @var string 95 | */ 96 | protected $domain; 97 | 98 | /** 99 | * Consturctor 100 | * @param string $clientId App's client id. 101 | * @param string $domain The domain where to save the session cookie. 102 | */ 103 | public function __construct($clientId, $domain = '') 104 | { 105 | parent::__construct($clientId); 106 | $this->domain = $domain; 107 | header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"'); 108 | } 109 | 110 | public function get($key, $default = false) 111 | { 112 | if (!in_array($key, self::$supportedKeys)) { 113 | return $default; 114 | } 115 | 116 | $name = $this->getKeyForStore($key); 117 | $value = $_COOKIE[$name]; 118 | if ($value && $key == 'session') { 119 | parse_str($value, $value); 120 | } 121 | if (empty($value)) { 122 | $value = $default; 123 | } 124 | 125 | return $value; 126 | } 127 | 128 | public function set($key, $value) 129 | { 130 | if (!in_array($key, self::$supportedKeys)) { 131 | return false; 132 | } 133 | 134 | $name = $this->getKeyForStore($key); 135 | if ($key == 'session') { 136 | $expires = isset($value['expires_in']) ? $value['expires_in'] * 2 : 3600*24; 137 | $value = http_build_query($value, '', '&'); 138 | } else { 139 | $expires = 3600*24; 140 | } 141 | 142 | setcookie($name, $value, time() + $expires, '/'); 143 | $_COOKIE[$name] = $value; 144 | 145 | return true; 146 | } 147 | 148 | public function remove($key) 149 | { 150 | if (!in_array($key, self::$supportedKeys)) { 151 | return false; 152 | } 153 | 154 | $name = $this->getKeyForStore($key); 155 | setcookie($name, 'delete', time() - 3600*24, '/'); 156 | unset($_COOKIE[$name]); 157 | 158 | return true; 159 | } 160 | 161 | public function removeAll() 162 | { 163 | foreach (self::$supportedKeys as $key) { 164 | $this->remove($key); 165 | } 166 | return true; 167 | } 168 | } 169 | 170 | /** 171 | * Storage engine using Session. 172 | */ 173 | class BaiduSessionStore extends BaiduStore 174 | { 175 | public function __construct($clientId) 176 | { 177 | if (!session_id()) { 178 | session_start(); 179 | } 180 | parent::__construct($clientId); 181 | } 182 | 183 | public function get($key, $default = false) 184 | { 185 | if (!in_array($key, self::$supportedKeys)) { 186 | return $default; 187 | } 188 | 189 | $name = $this->getKeyForStore($key); 190 | return isset($_SESSION[$name]) ? $_SESSION[$name] : $default; 191 | } 192 | 193 | public function set($key, $value) 194 | { 195 | if (!in_array($key, self::$supportedKeys)) { 196 | return false; 197 | } 198 | 199 | $name = $this->getKeyForStore($key); 200 | $_SESSION[$name] = $value; 201 | return true; 202 | } 203 | 204 | public function remove($key) 205 | { 206 | if (!in_array($key, self::$supportedKeys)) { 207 | return false; 208 | } 209 | 210 | $name = $this->getKeyForStore($key); 211 | unset($_SESSION[$name]); 212 | 213 | return true; 214 | } 215 | 216 | public function removeAll() 217 | { 218 | foreach (self::$supportedKeys as $key) { 219 | $this->remove($key); 220 | } 221 | return true; 222 | } 223 | } 224 | 225 | /** 226 | * Storage engine using memcached. 227 | */ 228 | class BaiduMemcachedStore extends BaiduStore 229 | { 230 | /** 231 | * Memcache instance 232 | * @var Memcache 233 | */ 234 | protected $memcache; 235 | 236 | /** 237 | * Session ID for current user to distinguish with other users. 238 | * @var string 239 | */ 240 | protected $sessionId; 241 | 242 | /** 243 | * @param string $clientId 244 | * @param Memcache $memcache 245 | */ 246 | public function __construct($clientId, $memcache, $sessionId) 247 | { 248 | $this->memcache = $memcache; 249 | $this->sessionId = $sessionId; 250 | 251 | parent::__construct($clientId); 252 | } 253 | 254 | public function get($key, $default = false) 255 | { 256 | if (!in_array($key, self::$supportedKeys)) { 257 | return $default; 258 | } 259 | 260 | $name = $this->getKeyForStore($key); 261 | $value = $this->memcache->get($name); 262 | return ($value === false) ? $default : $value; 263 | } 264 | 265 | public function set($key, $value) 266 | { 267 | if (!in_array($key, self::$supportedKeys)) { 268 | return false; 269 | } 270 | 271 | $name = $this->getKeyForStore($key); 272 | return $this->memcache->set($name, $value, 0, 0); 273 | } 274 | 275 | public function remove($key) 276 | { 277 | if (!in_array($key, self::$supportedKeys)) { 278 | return false; 279 | } 280 | 281 | $name = $this->getKeyForStore($key); 282 | return $this->memcache->delete($name); 283 | } 284 | 285 | public function removeAll() 286 | { 287 | foreach (self::$supportedKeys as $key) { 288 | $this->remove($key); 289 | } 290 | return true; 291 | } 292 | 293 | protected function getKeyForStore($key) 294 | { 295 | return implode('_', array('bds', $this->clientId, $this->sessionId, $key)); 296 | } 297 | } 298 | 299 | /* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */ -------------------------------------------------------------------------------- /wp2pcs/assets/manage-media.js: -------------------------------------------------------------------------------- 1 | jQuery(function($){ 2 | // 关闭文件信息框 3 | var $click = {}; 4 | $click.media_file = false; 5 | function close_file_info() { 6 | $('#wp2pcs-manage-media-page-files .file-on-pcs').removeClass('selected'); 7 | $('#wp2pcs-manage-media-page-file-info').hide(); 8 | } 9 | $('#wp2pcs-manage-media-page-file-info .close').on('click',function(e){ 10 | e.preventDefault(); 11 | close_file_info(); 12 | }); 13 | $(document).on('click',function() { 14 | if(!$click.media_file) close_file_info(); 15 | $click.media_file = false; 16 | }); 17 | // 点击上传按钮 18 | $('#wp2pcs-manage-media-btn-upload').on('click',function(e){ 19 | e.preventDefault(); 20 | var $this = $(this), 21 | $upload_box = $('#wp2pcs-manage-media-page-upload'); 22 | if($upload_box.is(':hidden')) { 23 | $('#wp2pcs-manage-media-page-content').hide(); 24 | close_file_info(); 25 | $upload_box.html('') 26 | $upload_box.fadeIn(500); 27 | } 28 | else { 29 | $upload_box.hide(); 30 | $('#wp2pcs-manage-media-page-content').fadeIn(500); 31 | } 32 | return false; 33 | }); 34 | // 顶部管理条固定位置 35 | function fixed_top_bar() { 36 | var $bar = $('#wp2pcs-manage-media-page-top-bar'), 37 | $content = $('#wp2pcs-manage-media-page-content'), 38 | width = $bar.width(), 39 | left = $content.offset().left; 40 | $bar.css({'position':'fixed','left':left + 'px','top':'30px','width':width + 'px'}); 41 | $content.css({'padding-top':'70px'}); 42 | } 43 | fixed_top_bar(); 44 | // 点击文件区域 45 | $(document).on('click','#wp2pcs-manage-media-page-files .file-on-pcs',function(e){ 46 | var $this = $(this), 47 | $file_info = $('#wp2pcs-manage-media-page-file-info'), 48 | root_dir = $('#wp2pcs-manage-media-page-check-root-dir').val(), 49 | file_format = $this.attr('data-file-format'), 50 | file_type = $this.attr('data-file-type'), 51 | file_name = $this.attr('data-file-name'), 52 | file_size = $this.attr('data-file-size'), 53 | file_path = $this.attr('data-file-path'), 54 | $child = $this.children(), 55 | file_url = $child.attr('data-url'), 56 | video_path = $child.attr('data-video-path'), 57 | is_vip = $('#wp2pcs-manage-media-page-check-vip').val(); 58 | $('#wp2pcs-manage-media-page-files .file-on-pcs').removeClass('selected'); 59 | $this.addClass('selected'); 60 | $file_info.find('.thumb').html(''); 61 | if(file_format == 'dir') { 62 | return true; 63 | } 64 | else if(file_format == 'image') { 65 | $file_info.find('.thumb').html(''); 66 | $file_info.find('.format').text('图像'); 67 | $file_info.find('.code').text(''); 68 | } 69 | else if(file_format == 'music') { 70 | $file_info.find('.format').text('音乐'); 71 | $file_info.find('.code').text('[audio src="' + file_url + '" poster="none" preload="none" loop="off" autoplay="off"]'); 72 | } 73 | else if(file_format == 'video') { 74 | $file_info.find('.format').text('视频'); 75 | if(is_vip) $file_info.find('.code').text(''); 76 | else $file_info.find('.code').text('[video width="" height="" src="' + file_url + '" poster="none" preload="none" loop="off" autoplay="off"]'); 77 | } 78 | else { 79 | $file_info.find('.format').text('文件'); 80 | $file_info.find('.code').text('点击下载'); 81 | } 82 | $file_info.find('.name').text(file_name); 83 | if(file_size/(1024*1024*1024) > 1) { 84 | file_size = (file_size/(1024*1024*1024)).toFixed(2) + 'GB'; 85 | } 86 | else if(file_size/(1024*1024) > 1) { 87 | file_size = (file_size/(1024*1024)).toFixed(2) + 'MB'; 88 | } 89 | else if(file_size/1024 > 1) { 90 | file_size = (file_size/1024).toFixed(2) + 'KB'; 91 | } 92 | else { 93 | file_size += 'B'; 94 | } 95 | $file_info.find('.size').text(file_size); 96 | $file_info.find('.path').text('路径:' + file_path); 97 | $file_info.find('.url').html('网址:' + file_url + ''); 98 | $file_info.show(); 99 | $click.media_file = true; 100 | }); 101 | $('#wp2pcs-manage-media-page-file-info textarea.code').on('click',function(){ 102 | $(this).select(); 103 | }); 104 | $('#wp2pcs-manage-media-page-top-bar').on('click',function() { 105 | $click.media_file = true; 106 | }); 107 | // 下拉加载 108 | $(window).scroll(function(){ 109 | var $window = $(window), 110 | scroll_top = $window.scrollTop(), 111 | screen_height = $window.height(), 112 | $pagenavi = $('#wp2pcs-manage-media-page-pagenavi'), 113 | $next = $pagenavi.find('a.next-page'), 114 | href = $next.attr('href'), 115 | loading = $pagenavi.attr('data-loading'), 116 | ajaxing = $pagenavi.attr('data-ajaxing'); 117 | if($pagenavi.length > 0 && scroll_top + screen_height + 100 > $pagenavi.offset().top && href != undefined) { 118 | 119 | if(ajaxing == 'true') return; 120 | $pagenavi.attr('data-ajaxing','true'); 121 | $.ajax({ 122 | url : href, 123 | dataType : 'html', 124 | type : 'GET', 125 | timeout : 10000, 126 | beforeSend : function() { 127 | $pagenavi.html(''); 128 | }, 129 | success : function(data) { 130 | var DATA = $(data), 131 | DATA = $('').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(''); 176 | }, 177 | success : function(data) { 178 | var DATA = $(data), 179 | DATA = $('').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 += ''; 123 | if(is_imglink) html += ''; 124 | } 125 | // 如果是视频 126 | else if($this.hasClass('file-format-video')) { 127 | if(is_videoplay) { 128 | html += '