From 6a122e3beda50c7f8ff74969675fd1aa1362cd53 Mon Sep 17 00:00:00 2001 From: Fabian de Boer Date: Fri, 17 Jul 2026 12:34:37 +0200 Subject: [PATCH 1/2] Brave request Fix. Path seperator fix. --- .gitignore | 1 + conf/init.php | 2 +- lib/ImgSearch.class.php | 2 +- resource/Brave.class.php | 19 +++++++++++++------ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 8c12c70..54e8b97 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ sessions/* ignore kanban/ .pi-tasks +docs/framework_review.md diff --git a/conf/init.php b/conf/init.php index ed0dbc1..c65b349 100755 --- a/conf/init.php +++ b/conf/init.php @@ -52,7 +52,7 @@ spl_autoload_register(function ($class_name) { } $include_path = get_include_path(); - $include_path_tokens = explode(':', $include_path); + $include_path_tokens = explode(PATH_SEPARATOR, $include_path); foreach ($include_path_tokens as $prefix) { $path[0] = $prefix . DIRECTORY_SEPARATOR . $class_name . '.interface.php'; diff --git a/lib/ImgSearch.class.php b/lib/ImgSearch.class.php index c1aaf46..9e9d44b 100755 --- a/lib/ImgSearch.class.php +++ b/lib/ImgSearch.class.php @@ -62,7 +62,7 @@ class ImgSearch { public function getImageData() { $clazz = ucfirst($this->engine); $search = new $clazz(); - $search->setQuery(urlencode($this->word)); + $search->setQuery($this->word); $search->setParam('start', $this->hitPosition); $search->setParam('size', $this->numberResults); diff --git a/resource/Brave.class.php b/resource/Brave.class.php index a55f164..74e727e 100644 --- a/resource/Brave.class.php +++ b/resource/Brave.class.php @@ -21,8 +21,20 @@ class Brave implements Search { public function setQuery($word) { $this->word = $word; + } - $request = $this->q_prefix . urlencode($word); + public function getData() { + $this->buildRequest(); + $return_array = $this->prepareData(); + return $return_array; + } + + /** + * Build the request URL and cURL handle after all setParam() calls have been made. + * This ensures start/offset and size are available when constructing the URL. + */ + private function buildRequest() { + $request = $this->q_prefix . urlencode($this->word); if (isset($this->start)) { $request .= '&offset=' . $this->start; } @@ -38,11 +50,6 @@ class Brave implements Search { $this->$key = $value; } - public function getData() { - $return_array = $this->prepareData(); - return $return_array; - } - /** * Prepare a project wide universal array with results */ From d185a26f874daf056bb7fb3b3ada023f6aec5d77 Mon Sep 17 00:00:00 2001 From: Fabian de Boer Date: Fri, 17 Jul 2026 21:58:05 +0200 Subject: [PATCH 2/2] default no debug. clever solution for api keys in git ignored local conf file. --- .gitignore | 1 + README.md | 15 ++++++++++++--- conf/conf.local.php.dist | 10 ++++++++++ conf/conf.php | 5 +++-- conf/init.php | 11 +++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 conf/conf.local.php.dist diff --git a/.gitignore b/.gitignore index 54e8b97..4dfc547 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ sessions/* +conf/conf.local.php ignore kanban/ .pi-tasks diff --git a/README.md b/README.md index 36f1b16..e45046a 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,22 @@ ApFab Zap Machine needs some PHP extensions: - CUrl (default installed) - Imagick (Image Magick image processing Class) -You need to acquire the following API key and put it into `conf/conf.php`: +You need to acquire the following API key: 1. **Brave Search API Key** - https://api.search.brave.com/ -See `conf/conf.php` for the exact constant names to use. +Then set up your configuration: -Adjust permission (chmod 777) for 'sessions' folder, run index.php in the www/ directory, fill in the form and voila. +```bash +# Create your local config from the template +cp conf/conf.local.php.dist conf/conf.local.php +# Edit it with your real keys +nano conf/conf.local.php +``` + +`conf/conf.local.php` is gitignored so your secrets stay safe. You can also set the `BRAVE_API_KEY` environment variable as an alternative. + +Adjust permission (chmod 777) for 'sessions' folder, then run index.php in the www/ directory, fill in the form and voila. # yet to come - Logfile also generated in imgProcess Class (0.9.2) diff --git a/conf/conf.local.php.dist b/conf/conf.local.php.dist new file mode 100644 index 0000000..a0c9fdb --- /dev/null +++ b/conf/conf.local.php.dist @@ -0,0 +1,10 @@ + environment variable > placeholder + */ +define('BRAVE_API_KEY', 'your-real-api-key-here'); \ No newline at end of file diff --git a/conf/conf.php b/conf/conf.php index f213c65..801c3e6 100755 --- a/conf/conf.php +++ b/conf/conf.php @@ -13,12 +13,13 @@ define('ZAP_CANVAS_NAME', 'collage'); define('ZAP_DELETE_SOURCE', false); define('ZAP_ADULT', false); define('ZAP_LOG', true); -define('ZAP_DEBUG', true); +define('ZAP_DEBUG', false); // Brave Search API // Get your API key: https://api.search.brave.com/ -define('BRAVE_API_KEY', 'your api key'); +// Put your key in conf/conf.local.php (gitignored) or set BRAVE_API_KEY env var +// See conf/conf.local.php.dist for a template define('BRAVE_BASE', 'https://api.search.brave.com/res/v1/images/search'); $search_engines = array('brave'); diff --git a/conf/init.php b/conf/init.php index c65b349..717c6f8 100755 --- a/conf/init.php +++ b/conf/init.php @@ -1,6 +1,17 @@