- neue Funktion: submitNewsToDb

geändert:       markdownExperiment/admin/newsAdmin.php
- Zeichensatzkonvertierung
	geändert:       markdownExperiment/wkParticipo/calendar.php
This commit is contained in:
marko
2018-07-28 13:03:34 +02:00
parent 0dae2f2078
commit a3234541c7
2 changed files with 63 additions and 81 deletions

View File

@@ -1,9 +1,9 @@
<?php
var_dump($_POST);
// Laden von Konfigurationsdaten
require_once("config.inc.php");
require_once($basePath."/bonus/db.inc");
// require_once($basePath."/bonus/db.inc");
require_once($basePath."/config/cwsvJudo.config.php");
require_once($basePath."/ressourcen/phpLib/cwsvJudo/newsLib.php");
require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php");
@@ -11,7 +11,64 @@ var_dump($_POST);
require_once($basePath."/ressourcen/phpLib/parsedown/Parsedown.php");
$Parsedown = new Parsedown();
function firstNonEmptyOf($somePossibleEmptyStuff){
if (is_array($somePossibleEmptyStuff) || $somePossibleEmptyStuff instanceof Traversable){
foreach($somePossibleEmptyStuff as $entry){
if(empty($entry))
continue;
else
return $entry;
}
}
return null;
}
// benötigt parsedown
function submitNewsToDb($aNews, $someOptions = array()){
// Standardargumente setzen
$someOptions['tableName'] = firstNonEmptyOf([$someOptions['tableName'], "cwsvjudo.nachrichtenDev"]);
$someOptions['newsCharset'] = firstNonEmptyOf([$someOptions['newsCharset'], "UTF-8"]);
$someOptions['dbCharset'] = firstNonEmptyOf([$someOptions['dbCharset'], "ISO-8859-1"]);
//@toDo: $aNews auf Validität testen
if($someOptions['dbConnection'])
$dbConnection = $someOptions['dbConnection'];
else{
try{
$dbConnection =
new PDO(
"mysql:host=".$someOptions['dbConfig']['host'].";dbname=".$someOptions['dbConfig']['name'],
$someOptions['dbConfig']['user'],
$someOptions['dbConfig']['password']
);
// set the PDO error mode to exception
// Warum weiß ich nicht mehr
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
echo( "Error: " . $e->getMessage() );
}
}
try{
// prepare sql and bind parameters
$stmt = $dbConnection->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'] = "http://cwsvjudo.bplaced.net/ressourcen/graphiken/logos/cwsvJudoLogoWappen.x256.png";
$defaultPromoImg['width'] = "207";
@@ -21,7 +78,6 @@ var_dump($_POST);
/// Auslesen des Newsarrays
if( empty($_POST['nachrichtenPromoImg']) )
$newsArticle['promoImg'] = $defaultPromoImg;
//$newsArticle['promoImg'] = null;
else{
$newsArticle['promoImg']['src'] = $_POST['nachrichtenPromoImg']['src'];
$newsArticle['promoImg']['width'] = $_POST['nachrichtenPromoImg']['width'];
@@ -30,7 +86,6 @@ var_dump($_POST);
if( !is_positive_integer($newsArticle['promoImg']['width']) || !is_positive_integer($newsArticle['promoImg']['height']) ){
$newsArticle['promoImg']['path'] = $basePath.urldecode(parse_url( $newsArticle['promoImg']['src'] )['path']);
if(file_exists( $newsArticle['promoImg']['path'] ) ){
var_dump($newsArticle['promoImg']['path']);
list(
$newsArticle['promoImg']['width'],
$newsArticle['promoImg']['height']
@@ -51,28 +106,7 @@ var_dump($_POST);
if( !empty($_POST['action']) ){
if( $_POST['action'] == "submitToDb" ){
try{
//@todo: config benutzen
$dbConnection = new PDO('mysql:host='.$db_server.';dbname='.$db_name, $db_user, $db_password);
// set the PDO error mode to exception
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $dbConnection->prepare("INSERT INTO cwsvjudo.nachrichtenDev (datum, betreff, nachricht, autor, promoImg) VALUES (:datum, :betreff, :nachricht, :autor, :promoImg)");
$stmt->bindParam(':datum', $newsArticle['datum']);
$stmt->bindParam(':betreff', iconv("UTF-8", "ISO-8859-1", $newsArticle['betreff']));
$stmt->bindParam(':nachricht', iconv("UTF-8", "ISO-8859-1", $Parsedown->text( $newsArticle['text'] )));
$stmt->bindParam(':autor', $newsArticle['autor']);
$stmt->bindParam(':promoImg', json_encode( $newsArticle['promoImg'] ) );
// insert a row
$stmt->execute();
echo "New records created successfully";
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
submitNewsToDb( $newsArticle, ['dbConfig' => $cwsvJudoConfig['db']] );
$dbConnection = null;
}
}
@@ -116,7 +150,6 @@ if( !empty($_POST['action']) ){
<?php echo(getHtmlNews(array(
'datum' => $newsArticle['datum'],
'betreff' => $newsArticle['betreff'],
// 'promoImg' => $newsArticle['promoImg']['url'],
'promoImg' => $newsArticle['promoImg'],
'nachricht' => Parsedown::instance()->text($newsArticle['text']),
'autor' => $newsArticle['autor']
@@ -215,7 +248,7 @@ if( !empty($_POST['action']) ){
<?php
try{
$dbConnection = new PDO('mysql:host='.$db_server.';dbname='.$db_name, $db_user, $db_password);
$dbConnection = new PDO('mysql:host='.$cwsvJudoConfig['db']['host'].';dbname='.$cwsvJudoConfig['db']['name'], $cwsvJudoConfig['db']['user'], $cwsvJudoConfig['db']['password']);
// set the PDO error mode to exception
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$newsList = getNews($dbConnection, array('limit'=>6));
@@ -229,57 +262,6 @@ if( !empty($_POST['action']) ){
echo("<hr />".getHtmlNews($news));
else echo("Keine Nachrichten gefunden!")
?>
<!--
<div class="newsArtikel" >
<div class="newsPromoImg" >
<?php
if( filter_var($newsArticle['promoImg']['url'], FILTER_VALIDATE_URL) )
echo( "<img src=\"".$newsArticle['promoImg']['url']."\" />" );
?>
</div>
<div class="newsDatum" >
<?php
echo($newsArticle['datum']);
?>
</div>
<div class="newsBetreff" >
<?php
echo($newsArticle['betreff']);
?>
</div>
<div class="newsText" >
<?php
echo( $Parsedown->text( $newsArticle['text'] ) );
?>
</div>
<div class="newsAutor" >
<?php
echo( $newsArticle['autor'] );
?>
</div>
</div>
-->
<div>
<!--
<?php
print_r(parse_url( !empty($_POST['nachrichtenPromoImgUrl'])?$_POST['nachrichtenPromoImgUrl']:$defaultPromoImg['url']));
?>
</div>
<div>
<?php
print_r(getimagesize( $basePath.urldecode( parse_url( !empty($_POST['nachrichtenPromoImgUrl'])?$_POST['nachrichtenPromoImgUrl']:$defaultPromoImg['url'] )['path'] ) ) );
?>
</div>
<div>
<?php if( empty($_POST) ) echo("No POST!"); else print_r($_POST);?>
</div>
<hr />
<div><h1>POST</h1><?php var_dump($_POST);?></div>
<div><h1>News</h1><?php var_dump($newsArticle);?></div>
<div><?php print_r(parse_url( !empty($_POST['nachrichtenPromoImgUrl'])?$_POST['nachrichtenPromoImgUrl']:$defaultPromoImg['url']));?></div>
<div><?php print_r(getimagesize( $basePath.urldecode( parse_url( !empty($_POST['nachrichtenPromoImgUrl'])?$_POST['nachrichtenPromoImgUrl']:$defaultPromoImg['url'] )['path'] ) ) );?></div>
-->
</body>
</html>

View File

@@ -21,7 +21,7 @@
exit();
}
$wkEvents = getCommingWkEvents( $mysqlConn );
$wkEvents = getCommingWkEvents( $mysqlConn, array('outCharset'=>"UTF-8") );
// iCal Datei zusammensetzen.
$ical = "BEGIN:VCALENDAR" . $eol .