From d9754149c1d27922c0b267e2bed723730e1ff481 Mon Sep 17 00:00:00 2001 From: Mark Chen <9006264+Mark9804@users.noreply.github.com> Date: Fri, 29 Jul 2022 12:47:48 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=8B=B1=E6=96=87=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + README.en.md | 50 ++++++++-------- doc/advance-usage.en.md | 24 ++++---- doc/deploy.en.md | 21 +++---- doc/log.en.md | 126 +++++++++++++++++++++++++++++++++++++++- 5 files changed, 176 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index a09c56d..90ac674 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.idea +.DS_Store diff --git a/README.en.md b/README.en.md index eb34c9c..a12d668 100644 --- a/README.en.md +++ b/README.en.md @@ -2,17 +2,17 @@

δΈ­ζ–‡

- Want to add a Pixiv Daily Ranking Widget to your website? Now, it only takes one line code to do it! + Want to add a Pixiv Daily Ranking Widget to your website? Now, it only takes one line of code to do it! DEMO

## ✨ Features -- Easy to use by only one `HTML` code -- Adaptive width and height. Recommended width `240px`, height `380px` or more -- Click the image redirect to detail page +- Easy to use with one line of `HTML` code +- Adaptive width and height. Recommended minimum size `240px * 380px` (width \* height) or more +- Clicking on the image will redirect to detailed page - Automatic daily update -- Built-in multi image-hosting support, on-demand image loading, extremely low resource consumption -- Provide API service, including ranking update date, thumbnail url and detail page url, etc. +- Builtin multi-image-hosting service provider support, on-demand image loading, extremely low resource consumption +- API service provided including ranking update date, thumbnail URL and detail page URL, etc. ## πŸ€” How to use Just add this line to your page @@ -20,15 +20,15 @@ Just add this line to your page ``` -Take `Wordpress` as an example. First go to `wp-admin`, click **Appearance** -> **Widgets** -Add a **Text** or **Custom HTML** widget to the right in the appropriate place and fill in the above code +Take `WordPress` as an example. On `wp-admin`, click on **Appearance** -> **Widgets** +Then add a **Text** or **Custom HTML** widget to the right in the appropriate place and fill in the code above [Advance Usage](doc/advance-usage.en.md) ## πŸ› οΈ How to deploy -Want to customize the code yourself? Think the service I provide is too slow? - -You can also easily have your own widget! +Want to customize the code yourself? Think the service I provided is too slow? + +You can also easily deploy your own widget! > Requires PHP version >= 5.6 [Deployment Documentation](doc/deploy.en.md) @@ -37,37 +37,37 @@ You can also easily have your own widget! [Ranking data (already uploaded to the image-hosting)](https://cloud.mokeyjay.com/pixiv/?r=api/pixiv-json) (recommended) [Ranking data (pixiv url)](https://cloud.mokeyjay.com/pixiv/?r=api/source-json) -`data` is the ranking data; `date` is the ranking date (maybe yesterday or the day before yesterday, because the official update time is not necessarily) - -Both api automatically return the corresponding cross-domain header based on the `Origin` or `Referer` in the request header. They can be called directly by the front-end +`data` is the ranking data; `date` is the ranking date (maybe yesterday or the day before yesterday, depending on the pixiv update time) + +Both API automatically return the corresponding cross-domain header based on the `Origin` or `Referer` in the request header. They are front-end ready. > The `image` and `url` keys are for compatibility with users of 4.x and earlier versions, you can ignore them ## πŸ†™ Upgrade Guide 1. [Download ZIP](https://github.com/mokeyjay/pixiv-daily-ranking-widget/releases/latest) -2. Unzip and overwrite the `app` and `index.php` to your server +2. Unzip and overwrite the `app` and `index.php` on your server ### From 4.x to 5.0 -1. Check the `image_hosting` item's comment from [config.php](config.php#L90), select the appropriate option and fill it in your `config.php` -2. Delete all files in 'storage/app', then let the program refresh the ranking data +1. Check the `image_hosting` item's comment from [config.php](config.php#L90), select the most appropriate image hosting option and fill it in your `config.php` +2. Delete all files in 'storage/app' to let the program refresh the ranking data ## 🌟 Changelog -### Added -- api service support cross-domain -- scheduled job to clearing historical logs -- support 8 free image-hosting +### New +- API service support cross-domain +- scheduled job to clear historical logs +- support 8 free image-hosting service provider ### Optimization - Picture display effect -- Left and right arrows will auto hidden now -- Show works title and author name when hovering +- Left and right arrows will autohide now +- Show works title and author name on mouse hover - Upgrade front-end dependency package to the latest, reduce dependency - Improve logging function - Enrich interface data to fit more scenarios - Replace Baidu statistics with Google statistics - Update default UA ### Fix -- the project url is not correctly retrieved in some cases -- download invalid picture in some cases +- Project URL cannot be retrieved correctly in some cases +- A blank image will be downloaded in some cases ### Other - Remove invalid Alibaba image-hosting diff --git a/doc/advance-usage.en.md b/doc/advance-usage.en.md index c77730f..918f096 100644 --- a/doc/advance-usage.en.md +++ b/doc/advance-usage.en.md @@ -5,25 +5,29 @@ ## Custom width or height This widget supports adaptive width and height. You only need to change the value of `width` or `height` in the code -For example, if you want 300 width and 500 height, then change the above code from -`width:240px; height:380px;` to `width:300px; height:500px;` +For example, if you want a width of 300px and height of 500px , then change the code above from +`width:240px; height:380px;` -> Since most pixiv images are previewed at a resolution of about 240*380, there is usually no need to modify the width and height +to `width:300px; height:500px;` + +> Since most pixiv images are previewed at a resolution of about 240*380, there is usually no need to modify the width and height. ## Custom background color -The default background color is transparent. If you want to change the background color, you can add the URL parameter `color` +The default background color is transparent. If you want to change the background color, you can add a parameter `color` to the URL. For example, if you want a red background, then change the above code from -`/pixiv` to `/pixiv?color=f00` +`/pixiv` + +to `/pixiv?color=f00` -`f00` means red, supports 3 or 6-bit [HTML Color Codes](https://htmlcolorcodes.com/), without the # sign +`f00` means red, supports 3- or 6-digit [HTML Color Codes](https://htmlcolorcodes.com/), **without the # sign** -## Customize the number -By default, only the top 50 entries are displayed. You can change this with the url parameter `limit` -> limit to a maximum of 500, since the maximum number of Pixiv Ranking is 500 +## Customize the returned pic number +By default, only the top 50 entries are displayed. You can change this with the URL parameter `limit`. +> the limit has a maximum of 500 since the maximum order of Pixiv Ranking is 500. For example, if you only want the first 10, then change the above code from `/pixiv` to `/pixiv?limit=10` > ⚠️ This value cannot exceed the limit configuration in `config.php` -> 🌟 To use more than one URL argument at a time, you can concatenate them with `&`. Such as `?color=f00&limit=10` \ No newline at end of file +> 🌟 To use more than one URL argument at a time, you can connect them with `&`. Such as `?color=f00&limit=10` \ No newline at end of file diff --git a/doc/deploy.en.md b/doc/deploy.en.md index b281470..630e5cd 100644 --- a/doc/deploy.en.md +++ b/doc/deploy.en.md @@ -1,23 +1,24 @@ # Deployment - [Download source code](https://github.com/mokeyjay/Pixiv-daily-ranking-widget/releases/latest) -- Unzip to the web directory -- Edit `config.php` with a professional editor (e.g. `Visual Studio Code`, `Sublime`, etc., notepad is not allowed) and modify the configuration accordingly -- Give write permission to `storage` directory +- Unzip under your the web directory +- Edit `config.php` with a **professional** editor (e.g. `Visual Studio Code`, `Sublime`, etc., notepad is not allowed) and modify the configuration according to your own needs +- Grant write permission to `storage` directory -## Proactively trigger updates -By default, this widget will check if the ranking data is out of date every time it is accessed and make an additional request to trigger an automatic update if needed. Usually no intervention is required +## Trigger updates proactively +By default, this widget will check if the ranking data is out of date every time it is accessed and make an additional request to trigger an automatic update if needed. In most cases, this operation is not required. -However, in some cases (e.g. PHP timeouts are not long enough, server performance is low), this web-triggered update is interrupted before it finishes, which not only causes the update to never finish, but also keeps wasting performance and bandwidth. -If you encounter the same problem, you can turn off web-triggered updates (set `disable_web_job` to `false` in `config.php`) +However, in some cases (e.g. PHP timeouts are not long enough, server performance is too poor), this web-triggered update will be interrupted before it finishes. This will interrupt the update and never let it finish, and also keeps consuming unnecessary performance and bandwidth. +If you encounter the problem above, you can turn off web-triggered updates (set `disable_web_job` to `false` in `config.php`) Then trigger update proactively via cli, e.g. `php index.php -j=refresh` > You can use a tool like `crontab` to automatically trigger updates on a regular basis. For example `*/30 * * * * php /path/to/pixiv/index.php -j=refresh` > It means run update every 30 minutes. The program will automatically determine whether it really needs to be updated, and it won't waste performance ## Clear the log at regular intervals -Opening the log (set `log_level` to `['DEBUG', 'ERROR']` in `config.php`) will log this widget's running info -When giving me feedback on a problem, it is also usually recommended to send me the logs and configuration file as a package (please do not post the configuration file to the public) -If you are going to keep the log open for a long time and are worried about it taking up too much hard drive, you can delete the 7 day old log with `php index.php -j=clear-log` +Opening the log (set `log_level` to `['DEBUG', 'ERROR']` in `config.php`) will log this widget's running info. +When giving me feedback on a problem, it is usually recommended to send me the logs and configuration file as a zip package (please do not post the configuration file to the public) +If you are going to keep the log enabled for a long time and are worried about it taking up too much hard drive, you can delete the logs over 7 days with `php index.php -j=clear-log` + > Add the parameter `-n=3` to delete logs that are 3 days old > You can use a tool like `crontab` to delete automatically on a regular basis. For example `30 1 * * * php /path/to/pixiv/index.php -j=clear-log` \ No newline at end of file diff --git a/doc/log.en.md b/doc/log.en.md index 83a2012..b10e440 100644 --- a/doc/log.en.md +++ b/doc/log.en.md @@ -1,2 +1,126 @@ # History Update Log -*There are so many history logs that I am too lazy to translate them* \ No newline at end of file +### 4.4.2 + +- Update default UA of Curl class +- Remove invalid image host +- Update Alibaba image host +- Add `disable_web_job` switch, see `config.php` for details + +### 4.4.1 + +- Update default UA of Curl class +- Fix an error of getting wrong project URL in some cases +- Fix the retry loop when fails to get ranking data. +- Optimize the logic to determine whether the data needs to be updated +- Delete the obsolete Alibaba image host + +### 4.4 + +- Use official ajax interface to get ranking data +- Add Alibaba, Baidu, toutiao.com image host API +- Update smms image host API to v2 version +- Remove deprecated img.sb image host API +- Remove unaccessible Jingdong image host API +- Remove statistics code on loading page +- Use comprehensive ranking data instead of just illustrations rank +- Expanded maximum number of returned images to 500, corresponding to the official limit +- The value of `service` configuration item no longer affects the limit. +- Other optimizations and bug fixes + +### 4.3 + +- Fix failed to update the Pixiv ranking page due to pixiv change. +- Use https when jumping to detail page + +### 4.2 + +- Fix failed to update the Pixiv ranking page due to pixiv change. +- Add a maximum number of retries if failing to get the ranking data. + +### 4.1 + +- Support transparent background + +### 4.0 + +- New version with almost all the codes rewritten, more new features and bugs for you to discover! +- Since pixiv has enabled global anti-hotlink, the `download` and `url_cache` options have been removed. Now it will force download thumbnails, and then upload them to the corresponding image host or store them locally on the server according to the configuration + +> Mumbling: I initially stated this project just for fun, and never expected the code to get so ugly as features piled up. It's so shameful that this project became my most starred project on GitHub. Luckily I spent some days to deal with the 4.0 version, and it feels better now. +> +> BTW this little thing now supports multiple image host, it will save hundreds of gigs of traffic every month now yingyingying + +### 3.0 + +- Add `$download_proxy` configuration option +- Since Pixiv's has enabled anti-hotlink and images cannot be displayed directly, `$download` is enabled by default. + For better display, self-deployed users are recommended to configure a timed task to trigger `download.php` at 0:00 every day + +### 2.9 + +- Fix the problem of not functioning normally due to Pixiv changes + +### 2.8 + +- Try to optimize update lock to prevent repeated updates under high concurrency +- Separate the configuration item `Conf::$url_cache` from `Conf::$download`, now you can only cache the image url instead of the thumbnail url +- Add support for tietuku.cn image host + +> The free version of tietuku.cn is not very good and does not support https, I suggest using sm.ms first and tietuku.cn only as a fallback option. +> Due to some problems with the previous update lock not working well under high concurrency, my server IP was blocked by sm.ms image host due to duplicate uploads. And I personally can't afford to support the high CDN cost. So effective immediately **Plan One** no longer provides official CDN acceleration and instead gets images directly from the Pixiv site Plan 1 is currently supported by 360 Site Defender CDN + +### 2.7 + +- Add image compression feature to reduce server bandwidth stress (requires GD library) +- Fix sm.ms image host support to reduce chances to fail +- Add sm.ms image host upload log + +> If there is a problem with opening `$enable_smms`, please paste the log file when giving feedback + +### 2.6 + +- Add sm.ms image host support. With one click to enable, it can significantly reduce the server bandwidth stress and save traffic. Thanks to [@Showfom](https://sb.sb/) for providing the image host + +> I'm not going to tell you that I added this feature because it hurts that the several gigabytes of traffic will be consumed every day on Plan 1 +> If the upload fails 3 times repeatedly, image will be read locally from the server to ensure normal access + +### 2.5 + +- Fix the problem of not functioning normally due to Pixiv changes +- Pixiv supports native https now! Hooray! + +### 2.4 + +- Fix the problem that the `limit` parameter of URL is invalid under certain circumstances +- Repair the caching problem of **Plan 1** +- Fix the SSL certificate problem + +### 2.3 + +- Replace the reference url of front-end library, fix the problem of slow loading with China Mobile as ISP +- Add adaptive protocol feature, fix the problem of the small green lock being affected when the cache is disabled or the cache peogress is not finished +- The above update comes from the friendly PR of @LingWuLuKong, let's PRPR her together to show our appreciation! +- The Plan One from mokeyJay a service now supports HTTPS. The CDN charge is high, please use and cherish! +- If it is abused to the point that I can not afford the cost, then the service may be suspended~ +- If the number of visits is high, it is recommended to build your own services, thank you for your support and understanding! + +### 2.2 + +- Optimize download threads to support self-deployed HTTPS + +### 2.1 + +- I must be drunk when planning the 2.0 roadmap to constrain all logic into one file. Although the overall performance has been improved, the same problems still occur in some cases. For example, the thumbnail will fail to download, PHP will timeout so the download will break, and so on. So when I tested it and realized this, I started working on a new version Facepalm. +- Remove the auto update lock mechanism, the thumbnails will no longer be re-downloaded when they already exist and are valid. Prevents thumbnail download failures due to network fluctuations or timeouts + +### 2.0 + +- Overall refactoring, overall performance is greatly optimized +- Add an automatic update lock mechanism to avoid wasting resources on concurrent updates under high concurrency scenario +- New pseudo multi-thread automatic update mechanism, background update does not affect widget use +- Update failure retrial, to avoid the failure of retrieving some images due to network problems + +## Motivations + +I was talking to a friend the other day, and he said he wanted to show the daily ranking of [Pixiv](http://www.pixiv.net/) in the sidebar of his blog. I am also an `ACG` lover myself, so I wanted to write this as well. I finally had time last night and spent more than half an hour writing it. It looks great on [my own blog](https://www.mokeyjay.com), so I polished it and added some features and made it open source in case you have the same requirements. \ No newline at end of file