Compare commits

...

2 commits

7 changed files with 53 additions and 13 deletions

2
.gitignore vendored
View file

@ -1,4 +1,6 @@
sessions/*
conf/conf.local.php
ignore
kanban/
.pi-tasks
docs/framework_review.md

View file

@ -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)

10
conf/conf.local.php.dist Normal file
View file

@ -0,0 +1,10 @@
<?php
/**
* Local configuration overrides — gitignored.
*
* Copy this file to conf/conf.local.php (without the .dist suffix)
* and fill in your real API keys.
*
* Priority: conf.local.php > environment variable > placeholder
*/
define('BRAVE_API_KEY', 'your-real-api-key-here');

View file

@ -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');

View file

@ -1,6 +1,17 @@
<?php
include_once 'conf.php';
// Load gitignored local overrides (API keys, debug toggle) if present
$localConf = __DIR__ . '/conf.local.php';
if (file_exists($localConf)) {
require_once $localConf;
}
// Fallback: try environment variable if still not defined
if (!defined('BRAVE_API_KEY')) {
define('BRAVE_API_KEY', getenv('BRAVE_API_KEY') ?: 'your api key');
}
/**
* Define some app-wide constants
*/
@ -52,7 +63,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';

View file

@ -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);

View file

@ -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
*/