- die Ausslagerung der promoImg der news scheint zu funktionieren

modified:   admin/newsAdmin.php
	modified:   phpLib/cwsvJudo/newsLib.php
This commit is contained in:
marko
2018-07-26 14:37:30 +02:00
parent d167dcd399
commit 0dae2f2078
2 changed files with 59 additions and 37 deletions

View File

@@ -1,5 +1,5 @@
<?php
var_dump($_POST);
// Laden von Konfigurationsdaten
require_once("config.inc.php");
@@ -13,33 +13,35 @@
$Parsedown = new Parsedown();
$defaultPromoImg['url'] = "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['height'] = "256";
/// Auslesen des Newsarrays
if( empty($_POST['nachrichtenPromoImgUrl']) )
//$newsArticle['promoImg'] = $defaultPromoImg;
$newsArticle['promoImg'] = null;
if( empty($_POST['nachrichtenPromoImg']) )
$newsArticle['promoImg'] = $defaultPromoImg;
//$newsArticle['promoImg'] = null;
else{
$newsArticle['promoImg']['url'] = $_POST['nachrichtenPromoImgUrl'];
$promoImgPath = $basePath.urldecode(parse_url( $newsArticle['promoImg']['url'] )['path']);
if(file_exists( $promoImgPath ) ){
// $newsArticle['promoImg']['width'] = getimagesize( $promoImgPath )[0];
// $newsArticle['promoImg']['height'] = getimagesize( $promoImgPath )[1];
list(
$newsArticle['promoImg']['width'],
$newsArticle['promoImg']['height']
) = array_slice( getimagesize( $promoImgPath ), 0, 2);
}
else{
$newsArticle['promoImg'] = null;
$newsArticle['promoImg']['src'] = $_POST['nachrichtenPromoImg']['src'];
$newsArticle['promoImg']['width'] = $_POST['nachrichtenPromoImg']['width'];
$newsArticle['promoImg']['height'] = $_POST['nachrichtenPromoImg']['heigth'];
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']
) = 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;
}
}
}
// print_r($newsArticle['promoImg']);
// echo(json_encode($newsArticle['promoImg']));
// print_r(json_decode(json_encode($newsArticle['promoImg'])));
// @todo Validierung!
$newsArticle['datum'] = !empty($_POST['nachrichtenDatum']) ? $_POST['nachrichtenDatum'] : strftime ( "%F" );
@@ -51,6 +53,7 @@ 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);
@@ -60,10 +63,8 @@ if( !empty($_POST['action']) ){
$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(':nachricht', $Parsedown->text( htmlspecialchars( $newsArticle['text'] ) ));
// $stmt->bindParam(':nachricht', iconv("UTF-8", "ISO-8859-1", $Parsedown->text($newsArticle['text'])));
$stmt->bindParam(':autor', $newsArticle['autor']);
$stmt->bindParam(':promoImg', $newsArticle['promoImg']['url']);
$stmt->bindParam(':promoImg', json_encode( $newsArticle['promoImg'] ) );
// insert a row
$stmt->execute();
@@ -115,7 +116,8 @@ if( !empty($_POST['action']) ){
<?php echo(getHtmlNews(array(
'datum' => $newsArticle['datum'],
'betreff' => $newsArticle['betreff'],
'promoImg' => $newsArticle['promoImg']['url'],
// 'promoImg' => $newsArticle['promoImg']['url'],
'promoImg' => $newsArticle['promoImg'],
'nachricht' => Parsedown::instance()->text($newsArticle['text']),
'autor' => $newsArticle['autor']
)));?>
@@ -132,10 +134,22 @@ if( !empty($_POST['action']) ){
name="nachrichtenBetreff"
><?php echo( htmlentities($newsArticle['betreff']) );?></textarea>
<input
id="nachrichtenPromoImgUrl"
name="nachrichtenPromoImgUrl"
id="nachrichtenPromoImg[src]"
name="nachrichtenPromoImg[src]"
type="hidden"
value="<?php echo($newsArticle['promoImg']['url']);?>"
value="<?php echo($newsArticle['promoImg']['src']);?>"
/>
<input
id="nachrichtenPromoImg[width]"
name="nachrichtenPromoImg[width]"
type="hidden"
value="<?php echo($newsArticle['promoImg']['width']);?>"
/>
<input
id="nachrichtenPromoImg[height]"
name="nachrichtenPromoImg[height]"
type="hidden"
value="<?php echo($newsArticle['promoImg']['height']);?>"
/>
<textarea class="noDisplay"
id="nachrichtenText"
@@ -175,8 +189,12 @@ if( !empty($_POST['action']) ){
</div>
<div>
<label for="nachrichtenPromoImgUrl">Url des Nachrichtenbildes</label>
<input id="nachrichtenPromoImgUrl" name="nachrichtenPromoImgUrl" type="text" value="<?php echo( empty($newsArticle['promoImg'])?"":$newsArticle['promoImg']['url'] );?>"/>
<label for="nachrichtenPromoImg[src]">SrcUrl des Nachrichtenbildes</label>
<input id="nachrichtenPromoImg[src]" name="nachrichtenPromoImg[src]" type="text" value="<?php echo( empty($newsArticle['promoImg']['src'])?"":$newsArticle['promoImg']['src'] );?>"/>
<label for="nachrichtenPromoImg[width]">width des Nachrichtenbildes</label>
<input id="nachrichtenPromoImg[width]" name="nachrichtenPromoImg[width]" type="text" value="<?php echo( empty($newsArticle['promoImg']['width'])?"":$newsArticle['promoImg']['width'] );?>"/>
<label for="nachrichtenPromoImg[height]">height des Nachrichtenbildes</label>
<input id="nachrichtenPromoImg[height]" name="nachrichtenPromoImg[height]" type="text" value="<?php echo( empty($newsArticle['promoImg']['height'])?"":$newsArticle['promoImg']['height'] );?>"/>
</div>
<div>

View File

@@ -38,19 +38,19 @@ $ret = array();
$query = "SELECT * FROM nachrichten";
if( is_positive_integer($optionsArray['jahr']) )
$query .= " WHERE DATE_FORMAT( datum, '%Y') = :jahr ORDER BY datum ASC, nr ASC";
else
$query .= " ORDER BY datum DESC, nr DESC LIMIT :limit;";
$query .= " WHERE DATE_FORMAT( datum, '%Y') = :jahr";
$query .= " ORDER BY datum DESC, nr DESC LIMIT :limit;";
//echo( $query );
$pdoStatementForQuerryingNews = $aMysqlConn->prepare(
$query
);
}
if( is_positive_integer($optionsArray['jahr']) )
$pdoStatementForQuerryingNews->bindParam(':jahr', intval($optionsArray['jahr']), PDO::PARAM_INT);
else
$pdoStatementForQuerryingNews->bindParam(':limit', intval($optionsArray['limit']), PDO::PARAM_INT);
$pdoStatementForQuerryingNews->bindParam(':limit', intval($optionsArray['limit']), PDO::PARAM_INT);
// $pdoStatementForQuerryingNews->bindParam(':jahr', intval($optionsArray['jahr']), PDO::PARAM_INT);
$pdoStatementForQuerryingNews->execute();
$ret = $pdoStatementForQuerryingNews->fetchAll(PDO::FETCH_ASSOC);
@@ -90,9 +90,13 @@ $options = getKeyValueArray($someOptions);
$retHtml .= "</div>";
$retHtml .= "<div class=\"newsBody\">";
// phpMyAdmin fügte manchmal die falschen Zeilenenden ein
$aNews['nachricht'] = str_replace("\r\n", "\n", $aNews['nachricht']);
if( !filter_var($aNews['promoImg'], FILTER_VALIDATE_URL) ){
// falls KEIN explizites PromoImage gesetzt ist, versuche es aus dem
// Nachrichtentext heraus zu lesen
// @toDo: woher bekomme ich width and height bei explizitem promoImg?
if( !filter_var($aNews['promoImg'], FILTER_VALIDATE_URL) || !filter_var($aNews['promoImg']['src'], FILTER_VALIDATE_URL) ){
$domDoc = new DOMDocument();
$domDoc->loadHTML( mb_convert_encoding($aNews['nachricht'], 'HTML-ENTITIES', "UTF-8") );
foreach($domDoc->getElementsByTagName('a') as $anchor){