0.9.0 - the ZapV version updated to current php standards. Brave search used, while Bing and Google search api are deprecated

This commit is contained in:
Fabian de Boer 2026-07-15 13:57:05 +02:00
commit 4ddaddda3d
31 changed files with 1778 additions and 1 deletions

35
conf/Config.class.php Executable file
View file

@ -0,0 +1,35 @@
<?php
/**
* Singleton configuration class
* Register configuration directives with this class
*/
class Config {
private static $instance = null;
private $config = array();
private function __construct() {
}
public static function getInstance() {
if (self::$instance === null) {
$clazz = __CLASS__;
self::$instance = new $clazz();
}
return self::$instance;
}
public function register($key, $value) {
$this->config[$key] = $value;
return;
}
public function retrieve($key) {
if (isset($this->config[$key])) {
return $this->config[$key];
} else {
return false;
}
}
}
?>

25
conf/conf.php Executable file
View file

@ -0,0 +1,25 @@
<?php
/**
* Local configuration directives here.
* Change as you like
*/
define('MAX_WORDS', 4);
define('MAX_ZAPS', 9);
define('ZAP_CURL_TIMEOUT', 12);
define('ZAP_IMG_TYPE', 'jpg');
define('ZAP_CANVAS_NAME', 'collage');
define('ZAP_DELETE_SOURCE', false);
define('ZAP_ADULT', false);
define('ZAP_LOG', true);
define('ZAP_DEBUG', true);
// Brave Search API
// Get your API key: https://api.search.brave.com/
define('BRAVE_API_KEY', 'your api key');
define('BRAVE_BASE', 'https://api.search.brave.com/res/v1/images/search');
$search_engines = array('brave');
?>

99
conf/init.php Executable file
View file

@ -0,0 +1,99 @@
<?php
include_once 'conf.php';
/**
* Define some app-wide constants
*/
define('ZAP_APP_BASE_DIR', realpath('.' . DIRECTORY_SEPARATOR . '..'));
define('ZAP_WEB_DIR', 'www');
define('ZAP_RESOURCE_DIR', 'resource');
define('ZAP_UTILS_DIR', 'utils');
define('ZAP_SESSIONS_DIR', 'sessions');
define('ZAP_LIB_DIR', 'lib');
define('ZAP_CONF_DIR', 'conf');
define('ZAP_TPL_DIR', 'tpl');
/**
* Error decoration
*/
define('ERROR_PREFIX', 'ZAP Error: ');
/**
* Set include path for application
*/
function setZAPIncludePath() {
$app_dirs = array(ZAP_RESOURCE_DIR, ZAP_UTILS_DIR, ZAP_SESSIONS_DIR,
ZAP_LIB_DIR, ZAP_TPL_DIR, ZAP_CONF_DIR);
$app_include_path = '';
foreach ($app_dirs as $app_dir) {
$app_include_path .= PATH_SEPARATOR . ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR . $app_dir;
}
if (set_include_path(get_include_path() . $app_include_path) == false) {
throw new Exception(ERROR_PREFIX . 'Error while creating include path...');
}
define('ZAP_INCLUDE_PATH_SET', true);
return;
}
/**
* Initiate autoload function for application
*/
spl_autoload_register(function ($class_name) {
if (!defined('ZAP_INCLUDE_PATH_SET') || ZAP_INCLUDE_PATH_SET === false) {
try {
setZAPIncludePath();
} catch (Exception $e) {
echo $e->getMessage();
die();
}
}
$include_path = get_include_path();
$include_path_tokens = explode(':', $include_path);
foreach ($include_path_tokens as $prefix) {
$path[0] = $prefix . DIRECTORY_SEPARATOR . $class_name . '.interface.php';
$path[1] = $prefix . DIRECTORY_SEPARATOR . $class_name . '.class.php';
foreach ($path as $thisPath) {
if (file_exists($thisPath)) {
require_once $thisPath;
return;
}
}
}
});
/**
* Define remaining app-wide constants
*/
define('ZAP_MOMENT', date("Y-m-d-H_i_s"));
define('ZAP_VERSION', '0.9.0');
define('ZAP_SESSION_NAME', 'ZAP');
// Only start session in web mode (not CLI)
if (php_sapi_name() !== 'cli') {
Session::start(ZAP_SESSION_NAME);
}
/**
* returns string of path of template file
* @return string
*/
function getZAPTemplate($tplname) {
if (!defined('ZAP_APP_BASE_DIR')) {
throw new Exception(ERROR_PREFIX . 'No base directory defined?!');
}
$tplfile = $tplname . '.tpl';
$tplfilepath = ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR
. ZAP_TPL_DIR . DIRECTORY_SEPARATOR . $tplfile;
if (file_exists($tplfilepath)) {
return $tplfilepath;
} else {
return ERROR_PREFIX . 'No template';
}
}
?>