prepare( "INSERT INTO " . $someOptions["tableName"] . " (datum, betreff, nachricht, autor, promoImg) VALUES (:datum, :betreff, :nachricht, :autor, :promoImg)", ); $stmt->bindParam(":datum", $aNews["datum"]); $stmt->bindParam( ":betreff", iconv( $someOptions["newsCharset"], $someOptions["dbCharset"], $aNews["betreff"], ), ); $stmt->bindParam( ":nachricht", iconv( $someOptions["newsCharset"], $someOptions["dbCharset"], Parsedown::instance()->text($aNews["text"]), ), ); $stmt->bindParam( ":autor", iconv( $someOptions["newsCharset"], $someOptions["dbCharset"], $aNews["autor"], ), ); $stmt->bindParam(":promoImg", json_encode($aNews["promoImg"])); // insert a row $stmt->execute(); echo "New records created successfully"; } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } return; } $defaultPromoImg = [ "src" => "/ressourcen/graphiken/logos/cwsvJudoLogoWappen.256w.png", "width" => "207", "height" => "256", "alt" => "cwsvJudo", ]; /// Auslesen des Newsarrays $newsArticle = []; if (empty($_POST["nachrichtenPromoImg"])) { $newsArticle["promoImg"] = $defaultPromoImg; } else { $newsArticle["promoImg"]["src"] = $_POST["nachrichtenPromoImg"]["src"]; $newsArticle["promoImg"]["width"] = $_POST["nachrichtenPromoImg"]["width"]; $newsArticle["promoImg"]["height"] = $_POST["nachrichtenPromoImg"]["heigth"] ?? null; if ( !is_positive_integer($newsArticle["promoImg"]["width"]) || !is_positive_integer($newsArticle["promoImg"]["height"]) ) { $newsArticle["promoImg"]["path"] = urldecode( parse_url($newsArticle["promoImg"]["src"])["path"], ); if (file_exists($newsArticle["promoImg"]["path"])) { [ $newsArticle["promoImg"]["width"], $newsArticle["promoImg"]["height"], ] = array_slice( getimagesize($newsArticle["promoImg"]["path"]), 0, 2, ); } else { // @todo: Wirklich nötig? Es könnte ja auch auf einem anderen Server liegen... // $newsArticle['promoImg'] = null; } } } // @todo Validierung! $newsArticle["datum"] = !empty($_POST["nachrichtenDatum"]) ? $_POST["nachrichtenDatum"] : date("Y-m-d"); $newsArticle["betreff"] = !empty($_POST["nachrichtenBetreff"]) ? $_POST["nachrichtenBetreff"] : "Kein Betreff!"; if (empty($newsArticle["promoImg"]["alt"])) { $newsArticle["promoImg"]["alt"] = $newsArticle["betreff"] . " (Promobildchen)"; } $newsArticle["text"] = !empty($_POST["nachrichtenText"]) ? $_POST["nachrichtenText"] : "Kein Text!"; $newsArticle["autor"] = !empty($_POST["nachrichtenAutor"]) ? $_POST["nachrichtenAutor"] : "Kein Autor!"; if (!empty($_POST["action"])) { if ($_POST["action"] == "submitToDb") { submitNewsToDb($newsArticle); $dbConnection = null; } } ?>