make it work: with cwsvjudo.de, in local docker and on remote heliohost

This commit is contained in:
marko
2025-06-23 16:58:14 +02:00
parent 754d5932b1
commit 5f9643c818
15 changed files with 40 additions and 244 deletions

View File

@@ -8,3 +8,5 @@ node_modules
# don't commit any secrets
Makefile.local
db_root_password.txt
db_password.txt

View File

@@ -15,7 +15,7 @@ configFiles = $(wildcard config/*.php)
LN = ln -f
.PHONY: all
all: build/css/cwsvJudo.css pages images
all: build/css/cwsvJudo.css images
# @todo This should only be temporary. Better outsource the graphics to it's own Makefile.
make -j graphiken
make build/css/cwsvJudo.css
@@ -29,9 +29,6 @@ build/graphiken/wallpapers/%.svg: graphiken/wallpapers/%.svg
.PHONY: images
images: $(wallpapers)
echo $(wallpapersSrc)
echo $(wallpapers)
.PHONY: clean
clean:
@@ -83,17 +80,11 @@ dist: all
$(LN) ./submodules/lazysizes/lazysizes.min.js $(distDir)/httpdocs/ressourcen/js/
# page data
mkdir -p $(distDir)/httpdocs/pages/responsive
find ./build/materialize/ -type f -exec $(LN) {} $(distDir)/httpdocs/pages/responsive \;
mkdir -p $(distDir)/httpdocs/pages/shared
find ./src/shared/ -type f -exec $(LN) {} $(distDir)/httpdocs/pages/shared \;
# testing/development pages
mkdir -p $(distDevPages)
mkdir -p $(distDevPages)/phpLibs/cwsvJudo
find src/pages/test -type f -exec $(LN) {} $(distDevPages) \;
find src/pages/test/phpLibs/cwsvJudo -type f -exec $(LN) {} $(distDevPages)/phpLibs/cwsvJudo \;
mkdir -p $(distWebRoot)/pages/responsive
find src/pages/responsive -type f -exec $(LN) {} $(distWebRoot)/pages/responsive \;
mkdir -p $(distWebRoot)/pages/responsive/phpLibs/cwsvJudo
find src/pages/responsive/phpLibs/cwsvJudo -type f -exec $(LN) {} $(distWebRoot)/pages/responsive/phpLibs/cwsvJudo \;
# structured data
mkdir -p $(distDir)/httpdocs/ressourcen/structuredData/json
@@ -194,6 +185,6 @@ build/css/cwsvJudo.css: $(cssFiles)
# curl
.PHONY: upload
upload: all
upload: dist
lftp -f scripts/upload-heliohost

View File

@@ -1,7 +1,7 @@
{
"cwsvJudo": {
"db": {
"host": "db",
"host": "localhost",
"name": "cwsvjudo_main",
"user": "cwsvjudo_marko"
}

View File

@@ -0,0 +1,9 @@
{
"cwsvJudo": {
"db": {
"host": "db",
"name": "cwsvjudo_main",
"user": "cwsvjudo_marko"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"cwsvJudo": {
"db": {
"cwsvjudo_marko": "kodokan"
}
}
}

View File

@@ -15,7 +15,8 @@ services:
volumes:
# this line maps the content of ./html in your pc to the /var/www/html of the container
- ./build/dist/heliohost/httpdocs:/var/www/html
- ./build/dist/heliohost/:/home/cwsvjudo.helioho.st/
- ./configs/localDocker/config.json:/home/cwsvjudo.de/.local/config.json
- ./configs/localDocker/secrets.json:/home/cwsvjudo.de/.local/secrets.json
db:
# check the mysql version you need for your project
image: mariadb:latest

View File

@@ -1,27 +1,11 @@
#! /usr/bin/env bash
open cwsvjudo.helioho.st
open cwsvjudo.de
user cwsvjudo CTI/eiT4RYe6?ac5
# @todo enable ssl check
set ssl:verify-certificate no
set ftp:ssl-allow off
# upload:
# - page data
mirror --verbose --continue --parallel=8 --reverse ./build/materialize /httpdocs/pages/responsive
# - php lib
mirror --verbose --continue --parallel=8 --reverse ./phpLib/cwsvJudo /httpdocs/ressourcen/phpLib/cwsvJudo
# - graphics
mirror --verbose --continue --parallel=8 --reverse ./build/graphiken /httpdocs/ressourcen/graphiken
mirror --verbose --continue --parallel=8 --reverse ./graphiken/banner /httpdocs/ressourcen/graphiken/banner
put build/graphiken/favIcons/favicon.ico -o /httpdocs/favicon.ico
# - css
mkdir -pf /httpdocs/ressourcen/css
put build/css/cwsvJudo.css -o /httpdocs/ressourcen/css/cwsvJudo.css
# - fonts
mirror --verbose --continue --parallel=8 --reverse ./res/fonts /httpdocs/ressourcen/fonts
# config files
put configs/heliohost/pages.config.inc.php -o /httpdocs/pages/responsive/config.inc.php
# @todo shouldn't be used any more
mkdir -pf /.local
mirror --verbose --continue --parallel=8 --reverse ./build/dist/heliohost /
put configs/heliohost/db.config.php -o /.local/db.config.php
# exit

View File

@@ -3,4 +3,4 @@
* home directory on the server
* - meaning the users home directory (aka ~) in the environment, not the directory served via http
*/
$home = "/home/cwsvjudo.helioho.st";
$home = "/home/cwsvjudo.de";

View File

@@ -19,8 +19,8 @@ $sections = [
dbHandle: $dbHandle,
options: [
"limit" => 6,
// "dbCharset" => "ISO-8859-1",
"dbCharset" => "UTF-8",
"dbCharset" => "ISO-8859-1",
// "dbCharset" => "UTF-8",
// "outCharset" => "ISO-8859-1",
"outCharset" => "UTF-8",
]
@@ -84,7 +84,7 @@ function main($sections, $wallpapers)
">" .
"</div>" .
"</div>";
echo '<div class="section">' . $section . "</div>";
echo '<div class="section container">' . $section . "</div>";
}
}
?>

View File

@@ -64,7 +64,9 @@ class PromoImage
{
public function __construct(array $data)
{
$this->src = filter_url($data["src"]);
// $this->src = filter_url($data["src"]);
// @todo php's url filter doesn't allow path only url
$this->src = $data["src"];
$this->height = filter_integer_range(
value: $data["height"],
min: 0,
@@ -130,18 +132,13 @@ class Entry
{
return '<div class="card horizontal">' .
'<div class="card-image">' .
'<span class="card-title">' .
$this->title .
"</span>" .
$this->promo->as_html() .
"</div>" .
'<div class="card-content">' .
'<span class="card-title">' .
$this->title .
"</span>" .
"<p>" .
$this->content .
"</p>" .
"</div>" .
"</div>";
}
@@ -225,12 +222,13 @@ function getNews(
function newsBoard(\CwsvJudo\Db\Connector $dbHandle, array $options): string
{
$boardHtml = '<div class=""><h2>Neuigkeiten</h2>';
$boardHtml = '<h2>Neuigkeiten</h2><div class="row">';
$entries = getNews(dbHandle: $dbHandle, options: $options);
if (!is_null($entries)) {
foreach ($entries as $entryData) {
$entry = new \CwsvJudo\News\Entry($entryData);
$boardHtml .= '<div class="">' . $entry->as_card() . "</div>";
$boardHtml .=
'<div class="col s12 l6">' . $entry->as_card() . "</div>";
}
}
$boardHtml .= "</div> ";

View File

@@ -1,193 +0,0 @@
<?php
namespace cwsvjudo\db;
/**
* interface for connecting and communicating with a database
*/
class Connector
{
// public
// - variables (none)
// - functions
public function connect(
string $hostname,
int $port = 3306,
string $dbName,
string $user,
string $password
): bool
{
return self::setDbConnection(
dbConnection: self::connectToPdo(
hostname: $hostname,
dbName: $dbName,
user: $user,
password: $password
)
);
}
// private
// - variables
/**
* pointer to the database connection
* @var
*
* Handle to interact with the database
*/
private $db = null;
// - functions
/** @todo Docu
* Establish a connection to the database
* @param mixed $hostname
* @param mixed $dbName
* @param mixed $user
* @param mixed $password
* @return \PDO|null
*/
private static function connectToPdo(
string $hostname,
int $port = 3306,
string $dbName,
string $user,
string $password
): \PDO|null
{
$dbConnection = null;
try {
$dbConnection = new \PDO(
dsn: 'mysql:'.join(
';',
[
'host=' . $hostname,
'port=' . strval($port),
'dbname=' . $dbName
]
),
username: $user,
password: $password
);
} catch(\PDOException $dbError) {
echo('Error whilst getting a dbConnection!: ' . $dbError->getMessage());
}
return $dbConnection;
}
public static function getDbConnection()
{
return self::$db;
}
/// perform a \PDO-query
///
/// @param $aQueryString
/// @param $aBindArray e.g. array(
/// ':userId' => array('value'=>$anUserId, 'data_type'=>\PDO::PARAM_INT),
/// ':attributeId'=> array('value'=>$anAttributeId, 'data_type'=>\PDO::PARAM_INT) )
/// @param $someOption
public static function query($aQueryString, $aBindArray = [], $someOptions = [])
{
// var_dump($aQueryString, $aBindArray);
// Standardbelegungen
if (empty($someOptions['dbCharset'])) {
$someOptions['dbCharset'] = 'ISO-8859-1';
}
if (empty($someOptions['outCharset'])) {
$someOptions['outCharset'] = 'UTF-8';
}
if (empty($someOptions['dontFetch'])) {
$someOptions['dontFetch'] = false;
}
$ignoreErrors = $someOptions['ignoreErrors'] ?? false;
/// @toDo: Bisher wird nur die Rückgabe konvertiert. Eigentlich muss
/// doch auch die Eingabe konvertiert werden. Aber das jetzt
/// umzustellen wird schwer! Die User im Wettkampfplaner sind ja z.B.
/// als UTF8 in latin1(?) gespeichert.
/// @toDo: Die Standardwerte sollten vielleicht aus einer config
/// kommen, nicht hardcoded
try {
$PDOStatement = self::$db->prepare($aQueryString);
foreach ($aBindArray as $bindName => $bind) {
if ($bind['data_type'] == \PDO::PARAM_STR) {
$bind['value'] = iconv(
$someOptions['outCharset'],
$someOptions['dbCharset'],
$bind['value']
);
}
$PDOStatement->bindValue(
$bindName,
$bind['value'],
(isset($bind['data_type']) ? $bind['data_type'] : \PDO::PARAM_STR)
);
}
$PDOResult = $PDOStatement->execute();
if (!$ignoreErrors && !$PDOResult) {
echo("Error during dbQuery!\n");
echo("DB-Error:\n");
var_dump(self::$db->errorInfo());
}
if ($someOptions['dontFetch']) {
$ret = null;
} else {
$ret = $PDOStatement->fetchAll(\PDO::FETCH_ASSOC);
}
} catch(\PDOException $db_error) {
print 'Error!: ' . $db_error->getMessage() . '<br/>';
return null;
}
// Zeichensatzkonvertierung
if (is_array($ret)) {
foreach ($ret as &$entry) {
array_walk(
$entry,
function (&$value, $key, $someOptions) {
$value = iconv($someOptions['dbCharset'], $someOptions['outCharset'], $value);
},
$someOptions
);
}
}
return $ret;
}
// @todo docu
public static function getLastInsertId()
{
return self::$db->lastInsertId();
}
// set the dbConnection (just setting, no establishing)
private function setDbConnection($dbConnection): bool
{
$success = false;
if ($dbConnection instanceof \PDO) {
self::$db = $dbConnection;
$success = true;
} else {
self::$db = null;
}
return $success;
}
public static function debugEchoQuery($query, $params)
{
foreach ($params as $key => $value) {
switch($value['data_type']) {
case \PDO::PARAM_STR:{
$query = str_replace($key, '\'' . $value['value'] . '\'', $query);
}
default:{
$query = str_replace($key, $value['value'], $query);
}
}
};
echo('query: ' . $query . PHP_EOL);
}
}

View File

@@ -1,3 +0,0 @@
<?php
namespace cwsvJudo\news;