Merge pull request #159 from mashirozx/dev

update to v3.3.3
This commit is contained in:
Mashiro 2019-12-13 15:41:52 +08:00 committed by GitHub
commit 5608a0d5fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 1798 additions and 1261 deletions

View File

@ -5,10 +5,10 @@
![Sakura](https://view.moezx.cc/images/2018/05/26/sakura.png)
![PHP version](https://img.shields.io/badge/PHP-7.1+-4F5B93.svg?style=flat-square)
![WP version](https://img.shields.io/badge/WordPress-5.0+-0073aa.svg?style=flat-square)
[![GitHub release](https://img.shields.io/github/release/mashirozx/Sakura.svg?style=flat-square)](https://github.com/mashirozx/Sakura/releases/latest)
[![Github commits (since latest release)](https://img.shields.io/github/commits-since/mashirozx/Sakura/latest.svg?style=flat-square)](https://github.com/mashirozx/Sakura/commits/)
![PHP version](https://shader.2heng.xin/badge/PHP-7.1+-4F5B93.svg?style=flat-square&logo=php)
![WP version](https://shader.2heng.xin/badge/WordPress-5.3-0073aa.svg?style=flat-square&logo=wordpress)
[![GitHub release](https://img.shields.io/github/v/release/mashirozx/Sakura.svg?style=flat-square&logo=github)](https://github.com/mashirozx/Sakura/releases/latest)
[![Github commits (since latest release)](https://img.shields.io/github/commits-since/mashirozx/Sakura/latest.svg?style=flat-square&logo=git&color=important)](https://github.com/mashirozx/Sakura/commits/)
[![](https://data.jsdelivr.com/v1/package/gh/moezx/cdn/badge)](https://www.jsdelivr.com/package/gh/moezx/cdn)
在 Louie 基于 Fuzzz 的 [Akina](http://www.akina.pw/themeakina) 主题修改的主题 [Siren](https://github.com/louie-senpai/Siren) 基础上三次修改 =.=

View File

@ -52,7 +52,7 @@ get_header(); ?>
</main><!-- #main -->
<?php if ( akina_option('pagenav_style') == 'ajax') { ?>
<div id="pagination" <?php if(akina_option('image_category') && is_category(explode(',',akina_option('image_category')))) echo 'class="pagination-archive"'; ?>><?php next_posts_link(__('Previous')); ?></div>
<div id="pagination" <?php if(akina_option('image_category') && is_category(explode(',',akina_option('image_category')))) echo 'class="pagination-archive"'; ?>><?php next_posts_link(' Previous'); ?></div>
<div id="add_post"><span id="add_post_time" style="visibility: hidden;" title="<?php echo akina_option('auto_load_post',''); ?>" ></span></div>
<?php }else{ ?>
<nav class="navigator">
@ -62,5 +62,4 @@ get_header(); ?>
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();

View File

@ -73,7 +73,7 @@ get_header();
</main><!-- #main -->
<?php if ( akina_option('pagenav_style') == 'ajax') { ?>
<div id="pagination"><?php next_posts_link(__('Previous')); ?></div>
<div id="pagination"><?php next_posts_link(' Previous'); ?></div>
<div id="add_post"><span id="add_post_time" style="visibility: hidden;" title="<?php echo akina_option('auto_load_post',''); ?>" ></span></div>
<?php }else{ ?>
<nav class="navigator">
@ -83,5 +83,4 @@ get_header();
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();

View File

@ -1,14 +0,0 @@
<?php
$img_array = glob("gallery/*.{gif,jpg,png}",GLOB_BRACE);
$img = array_rand($img_array);
$imgurl=$img_array[$img];
if($imgurl) {
header("Location: " . $imgurl);
exit();
} else {
exit('error');
}
?>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 486 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 KiB

View File

@ -1,14 +0,0 @@
<?php
$img_array = glob("gallery/*.{gif,jpg,png}",GLOB_BRACE);
$img = array_rand($img_array);
$imgurl=$img_array[$img];
if($imgurl) {
header("Location: " . $imgurl);
exit();
} else {
exit('error');
}
?>

View File

@ -7,7 +7,7 @@
* @package Sakura
*/
define( 'SAKURA_VERSION', '3.3.2' );
define( 'SAKURA_VERSION', '3.3.3' );
define( 'BUILD_VERSION', '3' );
//ini_set('display_errors', true);
@ -466,17 +466,18 @@ function restyle_text($number) {
}
function set_post_views() {
global $post;
$post_id = intval($post->ID);
$count_key = 'views';
$views = get_post_custom($post_id);
$views = array_key_exists("views",$views) ? intval($views['views'][0]) : 0;
if(is_single() || is_page()) {
if(!update_post_meta($post_id, 'views', ($views + 1))) {
add_post_meta($post_id, 'views', 1, true);
if (is_singular()) {
global $post;
$post_id = intval($post->ID);
if($post_id) {
$views = get_post_meta($post_id, 'views', true);
if(!update_post_meta($post_id, 'views', ($views + 1))) {
add_post_meta($post_id, 'views', 1, true);
}
}
}
}
add_action('get_header', 'set_post_views');
function get_post_views($post_id) {
@ -487,10 +488,7 @@ function get_post_views($post_id) {
return restyle_text(wp_statistics_pages('total','uri',$post_id));
}
} else {
$count_key = 'views';
$views = get_post_custom($post_id);
$views = array_key_exists("views",$views) ? intval($views['views'][0]) : 0;
$post_views = intval(post_custom('views'));
$views = get_post_meta($post_id, 'views', true);
if($views == '') {
return 0;
}else{
@ -1521,8 +1519,8 @@ function html_tag_parser($content) {
//With Thumbnail: !{alt}(url)[th_url]
if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content,$matches)){
$i=0;
foreach ($matches as $val) {
$content=str_replace($val[$i],preg_replace(
if ($i<sizeof($matches)) {
$content=str_replace($matches[$i],preg_replace(
'/!\{([^\{\}]+)*\}\('.$url_regex.'\)\['.$url_regex.'\]/i',
'<a data-fancybox="gallery"
data-caption="$1"
@ -1530,7 +1528,7 @@ function html_tag_parser($content) {
href="$2"
alt="$1"
title="$1"><img src="$7" target="_blank" rel="nofollow" class="fancybox"></a>',
$val[$i]),
$matches[$i]),
$content);
$i++;
}
@ -1559,6 +1557,30 @@ function html_tag_parser($content) {
',
$content
);
}
//html tag parser for rss
if(is_feed()) {
//Fancybox
$url_regex ='((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))';
if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content,$matches)){
$i=0;
if ($i<sizeof($matches)) {
$content=str_replace(
$matches[$i],
preg_replace('/!\{([^\{\}]+)*\}\('.$url_regex.'\)\['.$url_regex.'\]/i','<a href="$2"><img src="$7" alt="$1" title="$1"></a>',$matches[$i]),
$content
);
$i++;
}
}
$content=preg_replace('/!\{([^\{\}]+)*\}\('.$url_regex.'\)/i','<a href="$2"><img src="$2" alt="$1" title="$1"></a>',$content);
//Github cards
$content=preg_replace(
'/\[github repo=[\'"]([^\'"]+)[\'"]\]/i',
'<a href="https://github.com/$1">',
$content
);
}
return $content;
}
@ -1594,11 +1616,21 @@ function output_comments_qq_columns( $column_name, $comment_id ){
*/
add_filter( 'get_avatar', 'change_avatar', 10, 3 );
function change_avatar($avatar){
global $comment;
global $comment,$sakura_privkey;
if ($comment) {
if( get_comment_meta( $comment->comment_ID, 'new_field_qq', true )){
$qq_number = get_comment_meta( $comment->comment_ID, 'new_field_qq', true );
return '<img src="https://q2.qlogo.cn/headimg_dl?dst_uin='.$qq_number.'&spec=100" data-src="'.stripslashes($m[1]).'" class="lazyload avatar avatar-24 photo" alt="😀" width="24" height="24" onerror="imgError(this,1)">';
if(akina_option('qq_avatar_link')=='off'){
return '<img src="https://q2.qlogo.cn/headimg_dl?dst_uin='.$qq_number.'&spec=100" data-src="'.stripslashes($m[1]).'" class="lazyload avatar avatar-24 photo" alt="😀" width="24" height="24" onerror="imgError(this,1)">';
}elseif(akina_option('qq_avatar_link')=='type_3'){
$qqavatar = file_get_contents('http://ptlogin2.qq.com/getface?appid=1006102&imgtype=3&uin='.$qq_number);
preg_match('/:\"([^\"]*)\"/i',$qqavatar,$matches);
return '<img src="'.$matches[1].'" data-src="'.stripslashes($m[1]).'" class="lazyload avatar avatar-24 photo" alt="😀" width="24" height="24" onerror="imgError(this,1)">';
}else{
$encrypted = openssl_encrypt($qq_number, 'aes-128-cbc', $sakura_privkey, 0);
$encrypted = urlencode(base64_encode($encrypted));
return '<img src="'.rest_url("sakura/v1/qqinfo/avatar").'?qq='.$encrypted.'"class="lazyload avatar avatar-24 photo" alt="😀" width="24" height="24" onerror="imgError(this,1)">';
}
}else{
return $avatar ;
}
@ -1609,12 +1641,7 @@ function change_avatar($avatar){
// default feature image
function DEFAULT_FEATURE_IMAGE() {
if ( empty( akina_option('default_feature_image' )) ) {
return get_template_directory_uri().'/feature/index.php?'.rand(1,1000);
//return 'https://api.mashiro.top/feature/?'.rand(1,1000);
} else {
return akina_option('default_feature_image').'?'.rand(1,1000);
}
return rest_url('sakura/v1/image/feature').'?'.rand(1,1000);
}
//防止设置置顶文章造成的图片同侧bug
@ -1649,12 +1676,12 @@ function markdown_parser($incoming_comment) {
global $wpdb,$comment_markdown_content;
$re = '/```([\s\S]*?)```[\s]*|`{1,2}[^`](.*?)`{1,2}|\[.*?\]\([\s\S]*?\)/m';
if(preg_replace($re,'temp',$incoming_comment['comment_content']) != strip_tags(preg_replace($re,'temp',$incoming_comment['comment_content']))){
siren_ajax_comment_err('评论只支持Markdown啦见谅╮( ̄▽ ̄)╭<br>Markdown Supported while <i class="fa fa-code" aria-hidden="true"></i> Forbidden');
return( $incoming_comment );
siren_ajax_comment_err('评论只支持Markdown啦见谅╮( ̄▽ ̄)╭<br>Markdown Supported while <i class="fa fa-code" aria-hidden="true"></i> Forbidden');
return( $incoming_comment );
}
$myCustomer = $wpdb->get_row("SELECT * FROM wp_comments");
//Add column if not present.
if (!isset($myCustomer->say_state)) {
if (!isset($myCustomer->comment_markdown)) {
$wpdb->query("ALTER TABLE wp_comments ADD comment_markdown text");
}
$comment_markdown_content = $incoming_comment['comment_content'];
@ -1697,4 +1724,45 @@ function allow_more_tag_in_comment() {
$allowedtags['span'] = array('class'=>array());
}
add_action('pre_comment_on_post', 'allow_more_tag_in_comment');
/*
* 随机图
*/
function create_sakura_table(){
global $wpdb,$sakura_image_array,$sakura_privkey;
$sakura_table_name = $wpdb->base_prefix.'sakura';
require_once(ABSPATH . "wp-admin/includes/upgrade.php");
dbDelta("CREATE TABLE IF NOT EXISTS `" . $sakura_table_name . "` (
`mate_key` varchar(50) COLLATE utf8_bin NOT NULL,
`mate_value` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`mate_key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;");
//default data
if ( !$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'manifest_json'") ){
$manifest = array(
"mate_key" => "manifest_json",
"mate_value" => file_get_contents(get_template_directory()."/manifest/manifest.json")
);
$wpdb->insert($sakura_table_name,$manifest);
}
if ( !$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'json_time'") ){
$time = array(
"mate_key" => "json_time",
"mate_value" => date("Y-m-d H:i:s",time())
);
$wpdb->insert($sakura_table_name,$time);
}
if ( !$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'privkey'") ){
$privkey = array(
"mate_key" => "privkey",
"mate_value" => wp_generate_password(8)
);
$wpdb->insert($sakura_table_name,$privkey);
}
//reduce sql query
$sakura_image_array = $wpdb->get_var("SELECT `mate_value` FROM `wp_sakura` WHERE `mate_key`='manifest_json'");
$sakura_privkey = $wpdb->get_var("SELECT `mate_value` FROM `wp_sakura` WHERE `mate_key`='privkey'");
}
add_action( 'after_setup_theme', 'create_sakura_table' );
//code end

View File

@ -79,7 +79,6 @@ window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}
</head>
<body <?php body_class(); ?>>
<?php if(get_template_directory_uri() != get_site_url().'/wp-content/themes/Sakura') echo '<div style="position:fixed;height:100%;width:100%;top:0;left:0;font-size:20px;z-index:999999;background-color: #fff;">Plz rename the theme folder name as <span style="color:red">Sakura</span>!<br>请将主题文件夹名改为 <span style="color:red">Sakura</span></div>'; ?>
<?php if(!function_exists('curl_exec')) echo '<div style="position:fixed;height:100%;width:100%;top:0;left:0;font-size:20px;z-index:999999;background-color: #fff;">主题需要 PHP 的 curl 支持!请在 `php.ini` 里开启或者联系你的主机商。<br>The theme requires PHP\'s curl support! Please turn on in `php.ini` or contact your hosting provider.</div>'; ?>
<div class="scrollbar" id="bar"></div>
<section id="main-container">
<?php

View File

@ -4,62 +4,131 @@
* Router
*/
add_action('rest_api_init', function () {
register_rest_route('sakura/v1', '/image/upload', array(
'methods' => 'POST',
'callback' => 'upload_image',
));
register_rest_route('sakura/v1', '/cache_search/json', array(
'methods' => 'GET',
'callback' => 'cache_search_json',
));
register_rest_route('sakura/v1', '/image/upload', array(
'methods' => 'POST',
'callback' => 'upload_image',
));
register_rest_route('sakura/v1', '/cache_search/json', array(
'methods' => 'GET',
'callback' => 'cache_search_json',
));
register_rest_route('sakura/v1', '/image/cover', array(
'methods' => 'GET',
'callback' => 'cover_gallery',
));
register_rest_route('sakura/v1', '/image/feature', array(
'methods' => 'GET',
'callback' => 'feature_gallery',
));
register_rest_route('sakura/v1', '/database/update', array(
'methods' => 'POST',
'callback' => 'update_database',
));
register_rest_route('sakura/v1', '/qqinfo/json', array(
'methods' => 'GET',
'callback' => 'get_qq_info',
));
register_rest_route('sakura/v1', '/qqinfo/avatar', array(
'methods' => 'GET',
'callback' => 'get_qq_avatar',
));
});
/**
* QQ info
* https://sakura.2heng.xin/wp-json/sakura/v1/qqinfo/json
*/
function get_qq_info(WP_REST_Request $request)
{
if (!check_ajax_referer('wp_rest', '_wpnonce', false)) {
$output = array(
'status' => 403,
'success' => false,
'message' => 'Unauthorized client.'
);
} elseif ($_GET['qq']) {
$qq = $_GET['qq'];
/**
* TODO: 设置host国外服务器默认解析的不是国内IP可能无法获取数据
* 182.254.92.32 r.qzone.qq.com
* 参考https://www.php.net/manual/zh/function.file-get-contents.php#108309
*/
$get_info = file_get_contents('http://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?get_nick=1&uins=' . $qq);
$get_info = mb_convert_encoding($get_info, "UTF-8", "GBK");
$name = json_decode(substr($get_info, 17, -1), true);
if ($name) {
$output = array(
'status' => 200,
'success' => true,
'message' => 'success',
'avatar' => 'https://q.qlogo.cn/headimg_dl?dst_uin=' . $qq . '&spec=100',
'name' => $name[$qq][6],
);
} else {
$output = array(
'status' => 404,
'success' => false,
'message' => 'QQ number not exist.'
);
}
} else {
$output = array(
'status' => 400,
'success' => false,
'message' => 'Bad Request'
);
}
$result = new WP_REST_Response($output, $output['status']);
$result->set_headers(array('Content-Type' => 'application/json'));
return $result;
}
/**
* Image uploader response
*/
function upload_image(WP_REST_Request $request)
{
// see: https://developer.wordpress.org/rest-api/requests/
// see: https://developer.wordpress.org/rest-api/requests/
// handle file params $file === $_FILES
/**
* curl \
* -F "filecomment=This is an img file" \
* -F "cmt_img_file=@screenshot.jpg" \
* https://dev.2heng.xin/wp-json/sakura/v1/image/upload
*/
// $file = $request->get_file_params();
if ( !check_ajax_referer('wp_rest', '_wpnonce', false) ) {
$output = array(
'status' => 403,
'success' => false,
'message' => 'Unauthorized client.',
'link' => "https://view.moezx.cc/images/2019/11/14/step04.md.png",
'proxy' => akina_option('cmt_image_proxy') . "https://view.moezx.cc/images/2019/11/14/step04.md.png",
);
$result = new WP_REST_Response($output, 403);
// handle file params $file === $_FILES
/**
* curl \
* -F "filecomment=This is an img file" \
* -F "cmt_img_file=@screenshot.jpg" \
* https://dev.2heng.xin/wp-json/sakura/v1/image/upload
*/
// $file = $request->get_file_params();
if (!check_ajax_referer('wp_rest', '_wpnonce', false)) {
$output = array('status' => 403,
'success' => false,
'message' => 'Unauthorized client.',
'link' => "https://view.moezx.cc/images/2019/11/14/step04.md.png",
'proxy' => akina_option('cmt_image_proxy') . "https://view.moezx.cc/images/2019/11/14/step04.md.png",
);
$result = new WP_REST_Response($output, 403);
$result->set_headers(array('Content-Type' => 'application/json'));
return $result;
}
switch (akina_option("img_upload_api")) {
case 'imgur':
$image = file_get_contents($_FILES["cmt_img_file"]["tmp_name"]);
$API_Request = Imgur_API($image);
break;
case 'smms':
$image = $_FILES;
$API_Request = SMMS_API($image);
break;
case 'chevereto':
$image = file_get_contents($_FILES["cmt_img_file"]["tmp_name"]);
$API_Request = Chevereto_API($image);
break;
}
$result = new WP_REST_Response($API_Request, $API_Request['status']);
$result->set_headers(array('Content-Type' => 'application/json'));
return $result;
}
switch (akina_option("img_upload_api")) {
case 'imgur':
$image = file_get_contents($_FILES["cmt_img_file"]["tmp_name"]);
$API_Request = Imgur_API($image);
break;
case 'smms':
$image = $_FILES;
$API_Request = SMMS_API($image);
break;
case 'chevereto':
$image = file_get_contents($_FILES["cmt_img_file"]["tmp_name"]);
$API_Request = Chevereto_API($image);
break;
}
$result = new WP_REST_Response($API_Request, $API_Request->status);
$result->set_headers(array('Content-Type' => 'application/json'));
return $result;
}
/**
@ -67,21 +136,16 @@ function upload_image(WP_REST_Request $request)
*/
function Chevereto_API($image)
{
$fields = array(
'source' => base64_encode($image),
'key' => akina_option('chevereto_api_key')
$upload_url = akina_option('cheverto_url') . '/api/1/upload';
$args = array(
'body' => array(
'source' => base64_encode($image),
'key' => akina_option('chevereto_api_key'),
),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, akina_option('cheverto_url').'/api/1/upload');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$reply = curl_exec($ch);
curl_close($ch);
$reply = json_decode($reply);
$response = wp_remote_post($upload_url, $args);
$reply = json_decode($response["body"]);
if ($reply->status_txt == 'OK' && $reply->status_code == 200) {
$status = 200;
@ -112,18 +176,18 @@ function Chevereto_API($image)
function Imgur_API($image)
{
$client_id = akina_option('imgur_client_id');
$upload_url = akina_option('imgur_upload_image_proxy');
$args = array(
'headers' => array(
'Authorization' => 'Client-ID ' . $client_id,
),
'body' => array(
'image' => base64_encode($image),
),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, akina_option('imgur_upload_image_proxy'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image)));
$reply = curl_exec($ch);
curl_close($ch);
$reply = json_decode($reply);
$response = wp_remote_post($upload_url, $args);
$reply = json_decode($response["body"]);
if ($reply->success && $reply->status == 200) {
$status = 200;
@ -153,64 +217,48 @@ function Imgur_API($image)
*/
function SMMS_API($image)
{
$client_id = akina_option('smms_client_id');
$client_id = akina_option('smms_client_id');
$upload_url = "https://sm.ms/api/v2/upload";
$filename = $image['cmt_img_file']['name'];
$filedata = $image['cmt_img_file']['tmp_name'];
$Boundary = wp_generate_password();
$bits = file_get_contents($filedata);
$filename = $image['cmt_img_file']['name'];
$filedata = $image['cmt_img_file']['tmp_name'];
$filesize = $image['cmt_img_file']['size'];
$args = array(
"headers" => "Content-Type: multipart/form-data; boundary=$Boundary\r\n\r\nAuthorization: Basic $client_id\r\n\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97",
"body" => "--$Boundary\r\nContent-Disposition: form-data; name=\"smfile\"; filename=\"$filename\"\r\n\r\n$bits\r\n\r\n--$Boundary--"
);
$url = "https://sm.ms/api/v2/upload";
$headers = array();
array_push($headers, "Content-Type: multipart/form-data");
array_push($headers, "Authorization: Basic " . $client_id);
array_push($headers, "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97");
$response = wp_remote_post($upload_url, $args);
$reply = json_decode($response["body"]);
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mimetype = $finfo->file($filedata);
$fields = array('smfile' => curl_file_create($filedata, $mimetype, $filename));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$reply = curl_exec($ch);
curl_close($ch);
$reply = json_decode($reply);
if ($reply->success && $reply->code == 'success') {
$status = 200;
$success = true;
$message = $reply->message;
$link = $reply->data->url;
$proxy = akina_option('cmt_image_proxy') . $link;
} else if (preg_match("/Image upload repeated limit/i", $reply->message, $matches)) {
$status = 200; // sm.ms 接口不规范,建议检测到重复的情况下返回标准化的 code并单独把 url 放进一个字段
$success = true;
$message = $reply->message;
$link = str_replace('Image upload repeated limit, this image exists at: ', '', $reply->message);
$proxy = akina_option('cmt_image_proxy') . $link;
} else {
$status = 400;
$success = false;
$message = $reply->message;
$link = 'https://view.moezx.cc/images/2019/10/28/default_d_h_large.gif';
$proxy = akina_option('cmt_image_proxy') . $link;
}
$output = array(
'status' => $status,
'success' => $success,
'message' => $message,
'link' => $link,
'proxy' => $proxy,
);
return $output;
if ($reply->success && $reply->code == 'success') {
$status = 200;
$success = true;
$message = $reply->message;
$link = $reply->data->url;
$proxy = akina_option('cmt_image_proxy') . $link;
} else if (preg_match("/Image upload repeated limit/i", $reply->message, $matches)) {
$status = 200; // sm.ms 接口不规范,建议检测到重复的情况下返回标准化的 code并单独把 url 放进一个字段
$success = true;
$message = $reply->message;
$link = str_replace('Image upload repeated limit, this image exists at: ', '', $reply->message);
$proxy = akina_option('cmt_image_proxy') . $link;
} else {
$status = 400;
$success = false;
$message = $reply->message;
$link = 'https://view.moezx.cc/images/2019/10/28/default_d_h_large.gif';
$proxy = akina_option('cmt_image_proxy') . $link;
}
$output = array(
'status' => $status,
'success' => $success,
'message' => $message,
'link' => $link,
'proxy' => $proxy,
);
return $output;
}
/*
@ -262,8 +310,129 @@ EOS;
$data = '[' . $output . ']';
$result = new WP_REST_Response(json_decode($data), 200);
$result->set_headers(array('Content-Type' => 'application/json',
'Cache-Control' => 'max-age=3600')); // json 缓存控制
$result->set_headers(
array(
'Content-Type' => 'application/json',
'Cache-Control' => 'max-age=3600', // json 缓存控制
)
);
return $result;
}
/*
* 随机封面图 rest api
* @rest api接口路径https://sakura.2heng.xin/wp-json/sakura/v1/image/cover
*/
function cover_gallery() {
global $wpdb,$sakura_image_array;
$img_array = json_decode($sakura_image_array, true);
$img = array_rand($img_array);
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri();
if(strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')) {
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["webp"][0];
} else {
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["jpeg"][0];
}
$data = array('cover image');
$response = new WP_REST_Response($data);
$response->set_status(302);
$response->header('Location', $imgurl);
return $response;
}
/*
* 随机文章特色图 rest api
* @rest api接口路径https://sakura.2heng.xin/wp-json/sakura/v1/image/feature
*/
function feature_gallery() {
global $wpdb,$sakura_image_array;
$img_array = json_decode($sakura_image_array, true);
$img = array_rand($img_array);
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri();
if(strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')) {
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["webp"][1];
} else {
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["jpeg"][1];
}
$data = array('cover image');
$response = new WP_REST_Response($data);
$response->set_status(302);
$response->header('Location', $imgurl);
return $response;
}
/*
* update database rest api
* @rest api接口路径https://sakura.2heng.xin/wp-json/sakura/v1/database/update
*/
function update_database() {
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
$user = wp_authenticate($username, $password);
if (is_a($user, 'WP_User')) {
if (in_array('administrator', (array) $user->roles)) {
global $wpdb;
$sakura_table_name = $wpdb->base_prefix.'sakura';
if(isset($_FILES["manifest"])) {
$manifest = array(
"key" => "manifest_json",
"value" => file_get_contents($_FILES["manifest"]["tmp_name"])
);
$time = array(
"key" => "json_time",
"value" => date("Y-m-d H:i:s",time())
);
$wpdb->query("DELETE FROM `wp_sakura` WHERE `mate_key` ='manifest_json'");
$wpdb->query("DELETE FROM `wp_sakura` WHERE `mate_key` ='json_time'");
$wpdb->insert($sakura_table_name,$manifest);
$wpdb->insert($sakura_table_name,$time);
$message = "manifest.json has been stored into database.";
}
$output = array(
'status' => 200,
'success' => true,
'message' => $message
);
$result = new WP_REST_Response($output, 200);
$result->set_headers(array('Content-Type' => 'application/json'));
return $result;
}
} else {
$output = array(
'status' => 401,
'success' => false,
'message' => 'Not Authorized.'
);
$result = new WP_REST_Response($output, 401);
$result->set_headers(array('Content-Type' => 'application/json'));
return $result;
}
}
/**
* QQ头像链接解密
* https://sakura.2heng.xin/wp-json/sakura/v1/qqinfo/avatar
*/
function get_qq_avatar(){
global $sakura_privkey;
$encrypted=$_GET["qq"];
if(isset($encrypted)){
$encrypted = urldecode(base64_decode($encrypted));
$qq_number = openssl_decrypt($encrypted, 'aes-128-cbc', $sakura_privkey, 0);
preg_match('/^\d{3,}$/', $qq_number, $matches);
$imgurl='https://q2.qlogo.cn/headimg_dl?dst_uin='.$matches[0].'&spec=100';
if(akina_option('qq_avatar_link')=='type_2'){
$imgdata = file_get_contents($imgurl);
header("Content-type: image/jpeg");
header("Cache-Control: max-age=86400");
echo $imgdata;
}else{
$response = new WP_REST_Response();
$response->set_status(301);
$response->header('Location', $imgurl);
return $response;
}
}
}

View File

@ -78,15 +78,7 @@ if ( akina_option('toggle-menu') == 'no') { ?>
.comments .comments-hidden {display:none !important;}
<?php } // comments ?>
<?php
if (akina_option('cover_img')) {
$imgurl = akina_option('cover_img');
} else {
$imgurl = get_site_url()."/wp-content/themes/Sakura/cover/index.php";
}
$image_api = 'background-image: url("'.$imgurl.'");';
$image_api = 'background-image: url("'.rest_url('sakura/v1/image/cover').'");';
$bg_style = akina_option('focus_height') ? 'background-position: center center;background-attachment: inherit;' : '';
?>
.centerbg{<?php echo $image_api.$bg_style ?>background-position: center center;background-attachment: inherit;}

View File

@ -25,8 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/* If the user can't edit theme options, no use running this plugin */
define( 'SAKURA_OPTIONS', __('Sakura Options', 'sakura') );
add_action( 'init', 'optionsframework_rolescheck' );
function optionsframework_rolescheck () {
@ -181,8 +179,8 @@ function optionsframework_setdefaults() {
function optionsframework_menu_settings() {
$menu = array(
'page_title' => __( SAKURA_OPTIONS, 'optionsframework'),
'menu_title' => __( SAKURA_OPTIONS, 'optionsframework'),
'page_title' => __('Sakura Options', 'sakura'),
'menu_title' => __('Sakura Options', 'sakura'),
'capability' => 'edit_theme_options',
'menu_slug' => 'options-framework',
'callback' => 'optionsframework_page'
@ -262,7 +260,6 @@ if ( !function_exists( 'optionsframework_page' ) ) :
function optionsframework_page() { ?>
<div id="optionsframework-wrap" class="wrap">
<?php screen_icon( 'themes' ); ?>
<h2 class="nav-tab-wrapper">
<?php echo optionsframework_tabs(); ?>
</h2>
@ -275,7 +272,7 @@ function optionsframework_page() { ?>
<?php settings_fields( 'optionsframework' ); ?>
<?php optionsframework_fields(); /* Settings */ ?>
<div id="optionsframework-submit">
<input type="submit" class="button-primary" name="update" value="<?php esc_attr_e( 'Save', 'sakaura' ); ?>" />
<input type="submit" class="button-primary" name="update" value="<?php _e( 'Save', 'sakura' ); ?>" />
<input type="submit" class="reset-button button-secondary" name="reset" value="<?php esc_attr_e( 'Restore default', 'sakura' ); ?>" onclick="return confirm( '<?php print esc_js( __( 'All setting will be lost, sure?', 'sakura' ) ); ?>' );" />
<div class="clear"></div>
</div>
@ -412,7 +409,7 @@ function optionsframework_adminbar() {
$wp_admin_bar->add_menu( array(
'parent' => 'appearance',
'id' => 'of_theme_options',
'title' => __( SAKURA_OPTIONS, 'options_framework_theme' ),
'title' => __('Sakura Options', 'sakura'),
'href' => admin_url( 'themes.php?page=options-framework' )
));
}
@ -494,4 +491,4 @@ if ( ! function_exists( 'akina_option' ) ) {
return $default;
}
}
}

View File

@ -13,8 +13,8 @@ mashiro_option.site_name = "<?php echo akina_option('site_name', ''); ?>";
mashiro_option.author_name = "<?php echo akina_option('author_name', ''); ?>";
mashiro_option.template_url = "<?php echo get_template_directory_uri(); ?>";
mashiro_option.site_url = "<?php echo site_url(); ?>";
mashiro_option.qq_api_url = "https://api.2heng.xin/qqinfo/";
mashiro_option.qq_avatar_api_url = "https://api.2heng.xin/qqinfo/";
mashiro_option.qq_api_url = "<?php echo rest_url('sakura/v1/qqinfo/json'); ?>";
// mashiro_option.qq_avatar_api_url = "https://api.2heng.xin/qqinfo/";
mashiro_option.live_search = <?php if ( akina_option('live_search') ){ echo 'true'; } else { echo 'false'; } ?>;
<?php if( akina_option('sakura_skin_bg' )){ $bg_arry=explode(",", akina_option('sakura_skin_bg' ));?>
@ -71,13 +71,7 @@ mashiro_option.jsdelivr_css_src = "https://cdn.jsdelivr.net/gh/mashirozx/Sakura@
mashiro_option.float_player_on = true;
<?php endif; ?>
<?php
if (akina_option('cover_img')) {
$imgurl = akina_option('cover_img');
} else {
$imgurl = get_site_url()."/wp-content/themes/Sakura/cover/index.php";
} ?>
mashiro_option.cover_api = "<?php echo $imgurl; ?>";
mashiro_option.cover_api = "<?php echo rest_url('sakura/v1/image/cover'); ?>";
/*End of Initial Variables*/
</script>

View File

@ -43,11 +43,7 @@ function get_avatar_profile_url(){
* 随机图
*/
function get_random_bg_url(){
if ( empty( akina_option('default_feature_image' )) ) {
return get_template_directory_uri().'/feature/index.php?'.rand(1,1000);
} else {
return akina_option('default_feature_image').'?'.rand(1,1000);
}
return rest_url('sakura/v1/image/feature').'?'.rand(1,1000);
}
@ -118,7 +114,10 @@ if(akina_option('classify_display')){
*/
function comment_add_at( $comment_text, $comment = '') {
if( $comment->comment_parent > 0) {
$comment_text = '<a href="#comment-' . $comment->comment_parent . '" class="comment-at">@'.get_comment_author( $comment->comment_parent ) . '</a>&nbsp;' . $comment_text;
if(substr($comment_text, 0, 3) === "<p>")
$comment_text = str_replace(substr($comment_text, 0, 3), '<p><a href="#comment-' . $comment->comment_parent . '" class="comment-at">@'.get_comment_author( $comment->comment_parent ) . '</a>&nbsp;', $comment_text);
else
$comment_text = '<a href="#comment-' . $comment->comment_parent . '" class="comment-at">@'.get_comment_author( $comment->comment_parent ) . '</a>&nbsp;' . $comment_text;
}
return $comment_text;
}

View File

@ -64,7 +64,7 @@ get_header();
<?php else : get_template_part( 'tpl/content', 'none' ); endif; ?>
</main><!-- #main -->
<?php if ( akina_option('pagenav_style') == 'ajax') { ?>
<div id="pagination"><?php next_posts_link('Previous'); ?></div>
<div id="pagination"><?php next_posts_link(' Previous'); ?></div>
<div id="add_post"><span id="add_post_time" style="visibility: hidden;" title="<?php echo akina_option('auto_load_post',''); ?>" ></span></div>
<?php }else{ ?>
<nav class="navigator">

View File

@ -621,7 +621,7 @@ $(document).on("click", ".sm", function () {
if (confirm(msg) == true) {
$(this).commentPrivate();
} else {
aler("已取消");
alert("已取消");
}
});
$.fn.commentPrivate = function () {
@ -875,12 +875,10 @@ function getqqinfo() {
var qq = cached.filter('#author').val();
$.ajax({
type: 'get',
url: mashiro_option.qq_api_url + '?type=getqqnickname&qq=' + qq,
dataType: 'jsonp',
jsonp: 'callback',
jsonpCallback: 'portraitCallBack',
url: mashiro_option.qq_api_url + '?qq=' + qq + '&_wpnonce=' + Poi.nonce,
dataType: 'json',
success: function (data) {
cached.filter('#author').val(data[qq][6]);
cached.filter('#author').val(data.name);
cached.filter('#email').val($.trim(qq) + '@qq.com');
if (mashiro_option.qzone_autocomplete) {
cached.filter('#url').val('https://user.qzone.qq.com/' + $.trim(qq));
@ -892,12 +890,15 @@ function getqqinfo() {
$('.qq-check').css('display', 'block');
$('.gravatar-check').css('display', 'none');
}
setCookie('user_author', data[qq][6], 30);
setCookie('user_author', data.name, 30);
setCookie('user_qq', qq, 30);
setCookie('is_user_qq', 'yes', 30);
setCookie('user_qq_email', qq + '@qq.com', 30);
setCookie('user_email', qq + '@qq.com', 30);
emailAddressFlag = cached.filter('#email').val();
/***/
$('div.comment-user-avatar img').attr('src', data.avatar);
setCookie('user_avatar', data.avatar, 30);
},
error: function () {
cached.filter('#qq').val('');
@ -907,19 +908,7 @@ function getqqinfo() {
setCookie('user_qq', '', 30);
setCookie('user_email', cached.filter('#email').val(), 30);
setCookie('user_avatar', get_gravatar(cached.filter('#email').val(), 80), 30);
}
});
$.ajax({
type: 'get',
url: mashiro_option.qq_avatar_api_url + '?type=getqqavatar&qq=' + qq,
dataType: 'jsonp',
jsonp: 'callback',
jsonpCallback: 'qqavatarCallBack',
success: function (data) {
$('div.comment-user-avatar img').attr('src', data[qq]);
setCookie('user_avatar', data[qq], 30);
},
error: function () {
/***/
cached.filter('#qq,#email,#url').val('');
if (!cached.filter('#qq').val()) {
$('.qq-check').css('display', 'none');
@ -930,6 +919,27 @@ function getqqinfo() {
}
}
});
// $.ajax({
// type: 'get',
// url: mashiro_option.qq_avatar_api_url + '?type=getqqavatar&qq=' + qq,
// dataType: 'jsonp',
// jsonp: 'callback',
// jsonpCallback: 'qqavatarCallBack',
// success: function (data) {
// $('div.comment-user-avatar img').attr('src', data[qq]);
// setCookie('user_avatar', data[qq], 30);
// },
// error: function () {
// cached.filter('#qq,#email,#url').val('');
// if (!cached.filter('#qq').val()) {
// $('.qq-check').css('display', 'none');
// $('.gravatar-check').css('display', 'block');
// setCookie('user_qq', '', 30);
// $('div.comment-user-avatar img').attr('src', get_gravatar(cached.filter('#email').val(), 80));
// setCookie('user_avatar', get_gravatar(cached.filter('#email').val(), 80), 30);
// }
// }
// });
});
if (getCookie('user_avatar') && getCookie('user_email') && getCookie('is_user_qq') == 'no' && !getCookie('user_qq_email')) {
$('div.comment-user-avatar img').attr('src', getCookie('user_avatar'));

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

3
manifest/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Users\\Mashiro\\AppData\\Local\\Programs\\Python\\Python38\\python.exe"
}

47
manifest/README.md Normal file
View File

@ -0,0 +1,47 @@
封面图生成工具
===
### 依赖
Python3
PIL (Pillow)
### 安装依赖
安装 Python <https://docs.python.org/zh-cn/3.7/using/index.html>
安装 PIL
```bash
# Linix/Mac Terminal
pip install Pillow
# 如果也安装了 Python 2需要指定 pip 版本:
pip3 install Pillow
# Windows Powershell 或者 CMD
pip install Pillow
# 如果也安装了 Python 2需要指定 pip 版本:
pip3 install Pillow
# 如果提示权限不足([WinError 5] Access is denied请运行
pip install Pillow --user
```
用同样的方法安装`requests`
### 运行
把图片文件放到 `gallary` 目录Windows 可直接双击 manifest.py或者和其他操作系统一样在 Terminal、Powershell、CMD 中运行:
```bash
# 切换到 manifest.py 所在目录:
cd /path/to/manifest/
python manifest.py
# 如果也安装了 Python 2需要指定 Python 版本:
python3 manifest.py
```
GUI 程序开发中,除了以上运行 manifest.py 的方法以外,也可直接运行 qt.py 启动可视化窗口,需要安装 PyQT5
```bash
pip3 install PyQt5
python3 qt.py
```
### TODO
shell/batch 自动安装依赖、自动删除过期文件、压缩图片、GitHub API push、release

1
manifest/__init__.py Normal file
View File

@ -0,0 +1 @@
from .manifest import *

View File

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 131 KiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

BIN
manifest/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

BIN
manifest/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

1
manifest/manifest.json Normal file
View File

@ -0,0 +1 @@
{"19313b0d62b27c8ba022f60fbfedd5ee": {"source": "beyond_by_auroralion-dan5njb.jpg", "jpeg": ["jpeg/19313b0d62b27c8ba022f60fbfedd5ee.jpeg", "jpeg/19313b0d62b27c8ba022f60fbfedd5ee.th.jpeg"], "webp": ["webp/19313b0d62b27c8ba022f60fbfedd5ee.webp", "webp/19313b0d62b27c8ba022f60fbfedd5ee.th.webp"]}, "783bf161f47b32882f0e962fd4064de7": {"source": "pixar_up_movie_balloons_desktop_1920x1080_hd-wallpaper-507967.jpg", "jpeg": ["jpeg/783bf161f47b32882f0e962fd4064de7.jpeg", "jpeg/783bf161f47b32882f0e962fd4064de7.th.jpeg"], "webp": ["webp/783bf161f47b32882f0e962fd4064de7.webp", "webp/783bf161f47b32882f0e962fd4064de7.th.webp"]}, "e9f33c2c502ab43804964ce7edd431f9": {"source": "\u6d77\u306e\u7a7a(56993195)_by_\u590fT.jpg", "jpeg": ["jpeg/e9f33c2c502ab43804964ce7edd431f9.jpeg", "jpeg/e9f33c2c502ab43804964ce7edd431f9.th.jpeg"], "webp": ["webp/e9f33c2c502ab43804964ce7edd431f9.webp", "webp/e9f33c2c502ab43804964ce7edd431f9.th.webp"]}}

101
manifest/manifest.py Normal file
View File

@ -0,0 +1,101 @@
# coding=utf-8
'''
Created on Apr 23, 2018
Desc: Webp convertor
@author: Mashiro https://2heng.xin
'''
import os
import sys
import json
import requests
import base64
import hashlib
from PIL import Image
class Single(object):
def __init__(self, file, manifest):
self.file = file
self.mani = manifest
def hash(self):
hasher = hashlib.md5()
with open('gallary/' + self.file, 'rb') as afile:
buf = afile.read()
hasher.update(buf)
self.hash = hasher.hexdigest()
self.jpeg = 'jpeg/' + self.hash + '.jpeg'
self.webp = 'webp/' + self.hash + '.webp'
self.jpeg_th = 'jpeg/' + self.hash + '.th.jpeg'
self.webp_th = 'webp/' + self.hash + '.th.webp'
def optimize(self):
im = Image.open('gallary/' + self.file).convert('RGB')
im.save(self.jpeg, 'JPEG') # todo: TinyPNG API
im.save(self.webp, 'WEBP')
im.thumbnail((450, 300))
im.save(self.jpeg_th, 'JPEG') # todo: TinyPNG API
im.save(self.webp_th, 'WEBP')
def manifest(self):
self.mani[self.hash] = {
'source': self.file,
'jpeg': [self.jpeg, self.jpeg_th],
'webp': [self.webp, self.webp_th]
}
def main(self):
self.hash()
# if os.path.exists(self.jpeg) and os.path.exists(self.webp):
self.optimize()
self.manifest()
return self.mani
class Upload2Wordpress(object):
def __init__(self, username, password, url):
self.username = username
self.password = password
self.url = url
def upload(self, file, field):
data_string = self.username + ':' + self.password
token = base64.b64encode(data_string.encode()).decode('utf-8')
headers = {
'Authorization': 'Basic ' + token,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97"
}
files = {field: open(file, mode="rb")}
reply = requests.post(self.url, headers=headers, files=files)
print(json.loads(reply.content)['message'])
def main(self):
print('start uploading `manifest.json`...')
self.upload('manifest.json', 'manifest')
def gen_manifest_json():
onlyfiles = [f for f in os.listdir('gallary') if os.path.isfile(os.path.join('gallary', f))]
id = 1
Manifest = {}
for f in onlyfiles:
worker = Single(f, Manifest)
Manifest = worker.main()
print(str(id) + '/' + str(len(onlyfiles)))
id += 1
with open('manifest.json', 'w+') as json_file:
json.dump(Manifest, json_file)
def main():
gen_manifest_json()
username = input('Enter your username: ')
password = input('Enter your password: ')
url = input('Enter your rest api url: ')
upload = Upload2Wordpress(username, password, url)
upload.main()
if __name__ == '__main__':
main()
key = input('`manifest.json` saved. Press any key to quit.')
quit()

89
manifest/qt.py Normal file
View File

@ -0,0 +1,89 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Created on Nov 29, 2019
Desc: Webp convertor QT
@author: Mashiro @ https://2heng.xin
"""
import sys
import time
from PyQt5.QtWidgets import QMainWindow, QWidget, QApplication, QPushButton, QMessageBox, QDesktopWidget, QGridLayout
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtGui import QIcon
from manifest import main as manifest
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.statusBar().showMessage('Ready')
self.BtnWid = QWidget(self)
self.setCentralWidget(self.BtnWid)
grid = QGridLayout()
self.BtnWid.setLayout(grid)
names = ['Generate manifest.json',
'Pull from GitHub',
'Push to GitHub',
'Release on GitHub',
'Push manifest.json to WordPress',
'About and Turtor']
actions = [self.Action_1,
self.Action_0,
self.Action_0,
self.Action_0,
self.Action_0]
positions = [(i, j) for i in range(6) for j in range(1)]
for position, name, action in zip(positions, names, actions):
if name == '':
continue
button = QPushButton(name)
button.clicked.connect(action)
grid.addWidget(button, *position)
# self.resize(500, 500)
self.center()
self.setWindowTitle('Manifest Generator')
self.setWindowIcon(QIcon('icon.png'))
self.show()
def Action_0(self):
sender = self.sender()
self.statusBar().showMessage('"' + sender.text() + '" was pressed')
#Generate manifest.json
def Action_1(self):
# self.statusBar().showMessage('Processing...')
# time.sleep(1)
manifest()
self.statusBar().showMessage('`manifest.json` saved.')
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def closeEvent(self, event):
reply = QMessageBox.question(self, 'Message',
"Are you sure to quit?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec_())

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -262,13 +262,6 @@ function optionsframework_options() {
'right' => __('Right', 'sakura'),/*向右对齐*/
'alternate' => __('Alternate', 'sakura')/*左右交替*/
));
$options[] = array(
'name' => __('Default article feature image', 'sakura'),/*默认文章特色图*/
'desc' => __('The default image displayed without the article feature image set, use random cover if left blank (the image to be displayed is placed in the /wp-content/themes/Sakura/feature/gallery/ directory)', 'sakura'),/*在未设置文章特色图的情况下展示的默认图像,留空则调用本地随机封面(要展示的图片放入 /wp-content/themes/Sakura/feature/gallery/ 目录)*/
'id' => 'default_feature_image',
'std' => 'https://api.mashiro.top/feature/',
'type' => 'text');
$options[] = array(
'name' => __('Comment shrink', 'sakura'),/*评论收缩*/
@ -418,13 +411,6 @@ function optionsframework_options() {
'std' => '',
'type' => 'text');
$options[] = array(
'name' => __('Cover image', 'sakura'),/*封面图*/
'desc' => __('Leave this blank to use the built-in API (put the images that need to be randomly displayed into the /cover/gallery/ directory)', 'sakura'),/*此处留空则使用内置API将需要随机展示的图片放入 /cover/gallery/ 目录)*/
'id' => 'cover_img',
'std' => '',
'type' => 'text');
$options[] = array(
'name' => __('Background image filter', 'sakura'),/*背景图滤镜*/
'id' => 'focus_img_filter',
@ -748,13 +734,13 @@ function optionsframework_options() {
//后台配置
$options[] = array(
'name' => __('Background configuration', 'sakura'),/*后台配置*/
'name' => __('Dashboard configuration', 'sakura'),/*后台配置*/
'type' => 'heading' );
//后台面板自定义配色方案
$options[] = array(
'name' => __('Background panel custom color scheme', 'sakura'),/*后台面板自定义配色方案*/
'desc' => __('You can design the background panel (/wp-admin/) style yourself below, but before you start, please go to <a href="/wp-admin/profile.php">here</a> to change the color scheme to custom.(Custom).<br><b>Tip: </b>How to match colors? Maybe <a href="https://mashiro.top/color-thief/">this</a> can help you.', 'sakura'),/*你可以在下面自行设计后台面板(/wp-admin/)样式,不过在开始之前请到<a href="/wp-admin/profile.php">这里</a>将配色方案改为自定义Custom。<br><b>Tip: </b>如何搭配颜色?或许<a href="https://mashiro.top/color-thief/">这个</a>可以帮到你。*/
'name' => __('Dashboard panel custom color scheme', 'sakura'),/*后台面板自定义配色方案*/
'desc' => __('You can design the dashboard panel (/wp-admin/) style yourself below, but before you start, please go to <a href="/wp-admin/profile.php">here</a> to change the color scheme to custom.(Custom).<br><b>Tip: </b>How to match colors? Maybe <a href="https://mashiro.top/color-thief/">this</a> can help you.', 'sakura'),/*你可以在下面自行设计后台面板(/wp-admin/)样式,不过在开始之前请到<a href="/wp-admin/profile.php">这里</a>将配色方案改为自定义Custom。<br><b>Tip: </b>如何搭配颜色?或许<a href="https://mashiro.top/color-thief/">这个</a>可以帮到你。*/
'id' => 'scheme_tip',
'std' => '',
'type' => 'typography ');
@ -889,6 +875,13 @@ function optionsframework_options() {
'std' => '',
'type' => 'text');
$options[] = array(
'name' => __('Cover CDN', 'sakura'),/*封面图片库*/
'desc' => __('Fill in the cdn path for random picture display, without adding a slash at the end, for example: https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3, please refer to <a href = "https: //github.com/mashirozx/Sakura/wiki/options">Wiki </a>', 'sakura'),/*填写 cdn 路径用于随机图片展示最后不用加斜杠https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3 ,更多信息请参考<a href="https://github.com/mashirozx/Sakura/wiki/options">Wiki</a>*/
'id' => 'cover_cdn',
'std' => 'https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3',
'type' => 'text');
$options[] = array(
'name' => __('Use the front-end library locally (lib.js、lib.css)', 'sakura'),/*本地调用前端库lib.js、lib.css*/
'desc' => __('The front-end library don\'t load from jsDelivr, not recommand', 'sakura'),/*前端库不走 jsDelivr不建议启用*/
@ -910,7 +903,7 @@ function optionsframework_options() {
$options[] = array(
'name' => __('About', 'sakura'),/*关于*/
'desc' => __('Theme Sakura v'.SAKURA_VERSION.' | <a href="https://2heng.xin/theme-sakura/">Theme document</a> | <a href="https://github.com/mashirozx/Sakura/">Source code</a><a href="https://github.com/mashirozx/Sakura/releases/latest"><img src="https://img.shields.io/github/release/mashirozx/Sakura.svg?style=flat-square" alt="GitHub release"></a>', 'sakura'),/*Theme Sakura v'.SAKURA_VERSION.' | <a href="https://2heng.xin/theme-sakura/">主题说明</a> | <a href="https://github.com/mashirozx/Sakura/">源码</a><a href="https://github.com/mashirozx/Sakura/releases/latest"><img src="https://img.shields.io/github/release/mashirozx/Sakura.svg?style=flat-square" alt="GitHub release"></a>*/
'desc' => sprintf(__('Theme Sakura v %s | <a href="https://2heng.xin/theme-sakura/">Theme document</a> | <a href="https://github.com/mashirozx/Sakura/">Source code</a><a href="https://github.com/mashirozx/Sakura/releases/latest"><img src="https://img.shields.io/github/release/mashirozx/Sakura.svg?style=flat-square" alt="GitHub release"></a>', 'sakura'), SAKURA_VERSION),/*Theme Sakura v'.SAKURA_VERSION.' | <a href="https://2heng.xin/theme-sakura/">主题说明</a> | <a href="https://github.com/mashirozx/Sakura/">源码</a><a href="https://github.com/mashirozx/Sakura/releases/latest"><img src="https://img.shields.io/github/release/mashirozx/Sakura.svg?style=flat-square" alt="GitHub release"></a>*/
'id' => 'theme_intro',
'std' => '',
'type' => 'typography ');
@ -1039,7 +1032,7 @@ function optionsframework_options() {
$options[] = array(
'name' => __('Chevereto API v1 key', 'sakura'),
'desc' => __('Get your API key here '.akina_option('cheverto_url').'/dashboard/settings/api', 'sakura'),
'desc' => __('Get your API key here: '.akina_option('cheverto_url').'/dashboard/settings/api', 'sakura'),
'id' => 'chevereto_api_key',
'std' => '',
'type' => 'text');
@ -1067,14 +1060,14 @@ function optionsframework_options() {
$options[] = array(
'name' => __('Enable live search', 'sakura'),/*启用实时搜索*/
'desc' => __('Real-time search in the foreground, call the Rest API to update the cache every hour, you can manually set the cache time in functions.php'),/*前台实现实时搜索,调用 Rest API 每小时更新一次缓存,可在 functions.php 里手动设置缓存时间*/
'desc' => __('Real-time search in the foreground, call the Rest API to update the cache every hour, you can manually set the cache time in functions.php', 'sakura'),/*前台实现实时搜索,调用 Rest API 每小时更新一次缓存,可在 functions.php 里手动设置缓存时间*/
'id' => 'live_search',
'std' => '0',
'type' => 'checkbox');
$options[] = array(
'name' => __('Include comments in live search', 'sakura'),/*实时搜索包含评论*/
'desc' => __('Search for comments in real-time search (not recommended if there are too many comments on the site)'),/*在实时搜索中搜索评论(如果网站评论数量太多不建议开启)*/
'desc' => __('Search for comments in real-time search (not recommended if there are too many comments on the site)', 'sakura'),/*在实时搜索中搜索评论(如果网站评论数量太多不建议开启)*/
'id' => 'live_search_comment',
'std' => '0',
'type' => 'checkbox');
@ -1142,6 +1135,19 @@ function optionsframework_options() {
'std' => '0',
'type' => 'checkbox');
$options[] = array(
'name' => __('QQ avatar link encryption', 'sakura'),/*QQ头像链接加密*/
'desc' => __('Do not display the user\'s qq avatar links directly.', 'sakura'),/*不直接暴露用户qq头像链接*/
'id' => 'qq_avatar_link',
'std' => "off",
'type' => "select",
'options' => array(
'off' => __('Off (default)', 'sakura'),/*关闭(默认)*/
'type_1' => __('use redirect (general security)', 'sakura'),/*使用 重定向(安全性一般)'*/
'type_2' => __('fetch data at backend (high security)', 'sakura'),/*后端获取数据(安全性高)*/
'type_3' => __('fetch data at backend (high securityslow)', 'sakura'),/*后端获取数据(安全性高, 慢)*/
));
$options[] = array(
'name' => __('Comment UA infomation', 'sakura'),/*评论UA信息*/
'desc' => __('Check to enable, display the user\'s browser, operating system information', 'sakura'),/*勾选开启,显示用户的浏览器,操作系统信息*/

View File

@ -29,5 +29,4 @@ get_header(); ?>
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();

View File

@ -8,9 +8,7 @@
*/
//disable get_sidebar()
if ( is_active_sidebar( 'sakura_widget' ) ) {
return;
}
return;
?>
<aside id="secondary" class="widget-area" role="complementary">

View File

@ -23,5 +23,4 @@ get_header(); ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();

View File

@ -1,11 +1,11 @@
@charset "utf-8";
/*
Theme Name: Sakura
Theme URI: https://2heng.xin/theme-sakura/
Author: Mashiro, Louie, Fuzzz
Theme URI: https://github.com/mashirozx/Sakura/
Author: Mashiro, Spirit, Louie, Fuzzz
Author URI: http://2heng.xin
Description: A branch of theme Akina
Version: 3.3.2
Description: A wonderful branch of theme Akina
Version: 3.3.3
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: sakura
@ -8500,6 +8500,12 @@ h1[id*=toc-head]::before,h2[id*=toc-head]::before,h3[id*=toc-head]::before,h4[id
visibility:hidden
}
@media (max-width:860px) {
.widget-area{
display: none;
}
}
.widget-area {
position: fixed;
top: 100px;

View File

@ -23,7 +23,7 @@ if( !empty($_POST['register_reg']) ) {
if ( $user_email == '' ) {
$error .= '<strong>'.__("Error","sakura")./*错误*/'</strong>'.__("Please enter email address.","sakura")./*请填写电子邮件地址。*/'<br />';
} elseif ( ! is_email( $user_email ) ) {
$error .= '<strong>'.__("Error","sakura")./*错误*/'</strong>'.__("Invalid email address","sakura")./*电子邮件地址不正确。*/'<br />';
$error .= '<strong>'.__("Error","sakura")./*错误*/'</strong>'.__("Invalid email address.","sakura")./*电子邮件地址不正确。*/'<br />';
$user_email = '';
} elseif ( email_exists( $user_email ) ) {
$error .= '<strong>'.__("Error","sakura")./*错误*/'</strong>'.__("This email address has been registered.","sakura")./*该电子邮件地址已经被注册。*/'<br />';
@ -31,9 +31,9 @@ if( !empty($_POST['register_reg']) ) {
// Check the password
if(strlen($_POST['user_pass']) < 6){
$error .= '<strong>'.__("Error","sakura")./*错误*/'</strong>'.__("Password length is at least 6 digits","sakura")./*密码长度至少6位。*/'<br />';
$error .= '<strong>'.__("Error","sakura")./*错误*/'</strong>'.__("Password length is at least 6 digits.","sakura")./*密码长度至少6位。*/'<br />';
}elseif($_POST['user_pass'] != $_POST['user_pass2']){
$error .= '<strong>'.__("Error","sakura")./*错误*/'</strong>'.__("Inconsistent password entered twice","sakura")./*两次输入的密码不一致。*/'<br />';
$error .= '<strong>'.__("Error","sakura")./*错误*/'</strong>'.__("Inconsistent password entered twice.","sakura")./*两次输入的密码不一致。*/'<br />';
}
// verification
@ -89,7 +89,7 @@ if( !empty($_POST['register_reg']) ) {
<script>//window.location.href='<?php echo $loadurl; ?>';</script>
<?php } ?>
<?php else : ?>
<div class="register-close"><p><?php _e("Registration is not open yet","sakura")/*暂未开放注册。*/?></p></div>
<div class="register-close"><p><?php _e("Registration is not open yet.","sakura")/*暂未开放注册。*/?></p></div>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
@ -194,4 +194,4 @@ get_footer();
return milliSeconds;
}
</script>
<script type='text/javascript' src='<?php bloginfo("template_url"); ?>/user/verification.js'></script>
<script type='text/javascript' src='<?php bloginfo("template_url"); ?>/user/verification.js'></script>