From 0bf5dbbc0ba46cc27fe40b554b0c3c0ba705ef8b Mon Sep 17 00:00:00 2001
From: Dag ";
+
+ // Currently, this might result in broken image due to their strict referrer check
+ $item['content'] = sprintf('
', $img_url, $img_url);
// Additional content items
if (array_key_exists('pageCount', $result)) {
@@ -318,7 +318,7 @@ class PixivBridge extends BridgeAbstract
if (
!(strlen($proxy) > 0 && preg_match('/https?:\/\/.*/', $proxy))
) {
- return returnServerError('Invalid proxy_url value set. The proxy must include the HTTP/S at the beginning of the url.');
+ returnServerError('Invalid proxy_url value set. The proxy must include the HTTP/S at the beginning of the url.');
}
}
@@ -326,8 +326,7 @@ class PixivBridge extends BridgeAbstract
if ($cookie) {
$isAuth = $this->loadCacheValue('is_authenticated');
if (!$isAuth) {
- $res = $this->getData('https://www.pixiv.net/ajax/webpush', true, true)
- or returnServerError('Invalid PHPSESSID cookie provided. Please check the 🍪 and try again.');
+ $res = $this->getData('https://www.pixiv.net/ajax/webpush', true, true);
if ($res['error'] === false) {
$this->saveCacheValue('is_authenticated', true);
}
@@ -374,11 +373,11 @@ class PixivBridge extends BridgeAbstract
if ($cache) {
$data = $this->loadCacheValue($url);
if (!$data) {
- $data = getContents($url, $httpHeaders, $curlOptions, true) or returnServerError("Could not load $url");
+ $data = getContents($url, $httpHeaders, $curlOptions, true);
$this->saveCacheValue($url, $data);
}
} else {
- $data = getContents($url, $httpHeaders, $curlOptions, true) or returnServerError("Could not load $url");
+ $data = getContents($url, $httpHeaders, $curlOptions, true);
}
$this->checkCookie($data['headers']);
diff --git a/docs/10_Bridge_Specific/PixivBridge.md b/docs/10_Bridge_Specific/PixivBridge.md
index b782a445..ba8da2d8 100644
--- a/docs/10_Bridge_Specific/PixivBridge.md
+++ b/docs/10_Bridge_Specific/PixivBridge.md
@@ -2,9 +2,14 @@ PixivBridge
===============
# Image proxy
-As Pixiv requires images to be loaded with the `Referer "https://www.pixiv.net/"` header set, caching or image proxy is required to use this bridge.
-To turn off image caching, set the `proxy_url` value in this bridge's configuration section of `config.ini.php` to the url of the proxy. The bridge will then use the proxy in this format (essentially replacing `https://i.pximg.net` with the proxy):
+As Pixiv requires images to be loaded with the `Referer "https://www.pixiv.net/"` header set,
+caching or image proxy is required to use this bridge.
+
+To turn off image caching, set the `proxy_url` value in this bridge's configuration section of `config.ini.php`
+to the url of the proxy.
+
+The bridge will then use the proxy in this format (essentially replacing `https://i.pximg.net` with the proxy):
Before: `https://i.pximg.net/img-original/img/0000/00/00/00/00/00/12345678_p0.png`
@@ -15,9 +20,11 @@ proxy_url = "https://proxy.example.com"
```
# Authentication
-Authentication is required to view and search R-18+ and non-public images. To enable this, set the following in this bridge's configuration in `config.ini.php`.
-```
+Authentication is required to view and search R-18+ and non-public images.
+To enable this, set the following in this bridge's configuration in `config.ini.php`.
+
+```ini
; from cookie "PHPSESSID". Recommend to get in incognito browser.
cookie = "00000000_hashedsessionidhere"
```
\ No newline at end of file
diff --git a/index.php b/index.php
index c2c546a1..126200da 100644
--- a/index.php
+++ b/index.php
@@ -1,33 +1,14 @@
' . implode("\n", $errors) . '';
- exit(1);
-}
-
-$customConfig = [];
-if (file_exists(__DIR__ . '/config.ini.php')) {
- $customConfig = parse_ini_file(__DIR__ . '/config.ini.php', true, INI_SCANNER_TYPED);
-}
-Configuration::loadConfiguration($customConfig, getenv());
-
// Consider: ini_set('error_reporting', E_ALL & ~E_DEPRECATED);
date_default_timezone_set(Configuration::getConfig('system', 'timezone'));
-$rssBridge = new RssBridge();
-
set_exception_handler(function (\Throwable $e) {
- http_response_code(500);
- print render(__DIR__ . '/templates/exception.html.php', ['e' => $e]);
RssBridge::getLogger()->error('Uncaught Exception', ['e' => $e]);
- exit(1);
+ http_response_code(500);
+ exit(render(__DIR__ . '/templates/exception.html.php', ['e' => $e]));
});
set_error_handler(function ($code, $message, $file, $line) {
@@ -63,4 +44,6 @@ register_shutdown_function(function () {
}
});
+$rssBridge = new RssBridge();
+
$rssBridge->main($argv ?? []);
diff --git a/lib/CacheFactory.php b/lib/CacheFactory.php
index df78d9cb..90aa21ba 100644
--- a/lib/CacheFactory.php
+++ b/lib/CacheFactory.php
@@ -37,6 +37,7 @@ class CacheFactory
if ($index === false) {
throw new \InvalidArgumentException(sprintf('Invalid cache name: "%s"', $name));
}
+
$className = $cacheNames[$index] . 'Cache';
if (!preg_match('/^[A-Z][a-zA-Z0-9-]*$/', $className)) {
throw new \InvalidArgumentException(sprintf('Invalid cache classname: "%s"', $className));
diff --git a/lib/Configuration.php b/lib/Configuration.php
index ac7d29bf..ab1c9cdf 100644
--- a/lib/Configuration.php
+++ b/lib/Configuration.php
@@ -59,7 +59,7 @@ final class Configuration
}
$config = parse_ini_file(__DIR__ . '/../config.default.ini.php', true, INI_SCANNER_TYPED);
if (!$config) {
- throw new \Exception('Error parsing config');
+ throw new \Exception('Error parsing ini config');
}
foreach ($config as $header => $section) {
foreach ($section as $key => $value) {
diff --git a/lib/bootstrap.php b/lib/bootstrap.php
index 85d823e9..fe2069d3 100644
--- a/lib/bootstrap.php
+++ b/lib/bootstrap.php
@@ -1,5 +1,9 @@
' . implode("\n", $errors) . '');
+}
+
+$customConfig = [];
+if (file_exists(__DIR__ . '/../config.ini.php')) {
+ $customConfig = parse_ini_file(__DIR__ . '/../config.ini.php', true, INI_SCANNER_TYPED);
+}
+Configuration::loadConfiguration($customConfig, getenv());
diff --git a/lib/logger.php b/lib/logger.php
index 7a902b5b..e579915d 100644
--- a/lib/logger.php
+++ b/lib/logger.php
@@ -149,6 +149,7 @@ final class StreamHandler
);
error_log($text);
if ($record['level'] < Logger::ERROR && Debug::isEnabled()) {
+ // The record level is INFO or WARNING here
// Not a good idea to print here because http headers might not have been sent
print sprintf("
%s
\n", e($text));
}
diff --git a/phpcs.xml b/phpcs.xml
index 5e50470a..21e1f50a 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -1,6 +1,11 @@
+ The HTTP 403 Forbidden response status code indicates that the + server understands the request but refuses to authorize it. +
+ + getCode() === 404): ?>