- neue Funktion: submitNewsToDb
geändert: markdownExperiment/admin/newsAdmin.php - Zeichensatzkonvertierung geändert: markdownExperiment/wkParticipo/calendar.php
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
var_dump($_POST);
|
|
||||||
// Laden von Konfigurationsdaten
|
// Laden von Konfigurationsdaten
|
||||||
require_once("config.inc.php");
|
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/newsLib.php");
|
||||||
require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php");
|
require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php");
|
||||||
@@ -11,7 +11,64 @@ var_dump($_POST);
|
|||||||
require_once($basePath."/ressourcen/phpLib/parsedown/Parsedown.php");
|
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['src'] = "http://cwsvjudo.bplaced.net/ressourcen/graphiken/logos/cwsvJudoLogoWappen.x256.png";
|
||||||
$defaultPromoImg['width'] = "207";
|
$defaultPromoImg['width'] = "207";
|
||||||
@@ -21,7 +78,6 @@ var_dump($_POST);
|
|||||||
/// Auslesen des Newsarrays
|
/// Auslesen des Newsarrays
|
||||||
if( empty($_POST['nachrichtenPromoImg']) )
|
if( empty($_POST['nachrichtenPromoImg']) )
|
||||||
$newsArticle['promoImg'] = $defaultPromoImg;
|
$newsArticle['promoImg'] = $defaultPromoImg;
|
||||||
//$newsArticle['promoImg'] = null;
|
|
||||||
else{
|
else{
|
||||||
$newsArticle['promoImg']['src'] = $_POST['nachrichtenPromoImg']['src'];
|
$newsArticle['promoImg']['src'] = $_POST['nachrichtenPromoImg']['src'];
|
||||||
$newsArticle['promoImg']['width'] = $_POST['nachrichtenPromoImg']['width'];
|
$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']) ){
|
if( !is_positive_integer($newsArticle['promoImg']['width']) || !is_positive_integer($newsArticle['promoImg']['height']) ){
|
||||||
$newsArticle['promoImg']['path'] = $basePath.urldecode(parse_url( $newsArticle['promoImg']['src'] )['path']);
|
$newsArticle['promoImg']['path'] = $basePath.urldecode(parse_url( $newsArticle['promoImg']['src'] )['path']);
|
||||||
if(file_exists( $newsArticle['promoImg']['path'] ) ){
|
if(file_exists( $newsArticle['promoImg']['path'] ) ){
|
||||||
var_dump($newsArticle['promoImg']['path']);
|
|
||||||
list(
|
list(
|
||||||
$newsArticle['promoImg']['width'],
|
$newsArticle['promoImg']['width'],
|
||||||
$newsArticle['promoImg']['height']
|
$newsArticle['promoImg']['height']
|
||||||
@@ -51,28 +106,7 @@ var_dump($_POST);
|
|||||||
|
|
||||||
if( !empty($_POST['action']) ){
|
if( !empty($_POST['action']) ){
|
||||||
if( $_POST['action'] == "submitToDb" ){
|
if( $_POST['action'] == "submitToDb" ){
|
||||||
|
submitNewsToDb( $newsArticle, ['dbConfig' => $cwsvJudoConfig['db']] );
|
||||||
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();
|
|
||||||
}
|
|
||||||
$dbConnection = null;
|
$dbConnection = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +150,6 @@ if( !empty($_POST['action']) ){
|
|||||||
<?php echo(getHtmlNews(array(
|
<?php echo(getHtmlNews(array(
|
||||||
'datum' => $newsArticle['datum'],
|
'datum' => $newsArticle['datum'],
|
||||||
'betreff' => $newsArticle['betreff'],
|
'betreff' => $newsArticle['betreff'],
|
||||||
// 'promoImg' => $newsArticle['promoImg']['url'],
|
|
||||||
'promoImg' => $newsArticle['promoImg'],
|
'promoImg' => $newsArticle['promoImg'],
|
||||||
'nachricht' => Parsedown::instance()->text($newsArticle['text']),
|
'nachricht' => Parsedown::instance()->text($newsArticle['text']),
|
||||||
'autor' => $newsArticle['autor']
|
'autor' => $newsArticle['autor']
|
||||||
@@ -215,7 +248,7 @@ if( !empty($_POST['action']) ){
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
try{
|
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
|
// set the PDO error mode to exception
|
||||||
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
$newsList = getNews($dbConnection, array('limit'=>6));
|
$newsList = getNews($dbConnection, array('limit'=>6));
|
||||||
@@ -229,57 +262,6 @@ if( !empty($_POST['action']) ){
|
|||||||
echo("<hr />".getHtmlNews($news));
|
echo("<hr />".getHtmlNews($news));
|
||||||
else echo("Keine Nachrichten gefunden!")
|
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>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$wkEvents = getCommingWkEvents( $mysqlConn );
|
$wkEvents = getCommingWkEvents( $mysqlConn, array('outCharset'=>"UTF-8") );
|
||||||
|
|
||||||
// iCal Datei zusammensetzen.
|
// iCal Datei zusammensetzen.
|
||||||
$ical = "BEGIN:VCALENDAR" . $eol .
|
$ical = "BEGIN:VCALENDAR" . $eol .
|
||||||
|
|||||||
Reference in New Issue
Block a user