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

View File

@@ -38,19 +38,19 @@ $ret = array();
$query = "SELECT * FROM nachrichten"; $query = "SELECT * FROM nachrichten";
if( is_positive_integer($optionsArray['jahr']) ) if( is_positive_integer($optionsArray['jahr']) )
$query .= " WHERE DATE_FORMAT( datum, '%Y') = :jahr ORDER BY datum ASC, nr ASC"; $query .= " WHERE DATE_FORMAT( datum, '%Y') = :jahr";
else
$query .= " ORDER BY datum DESC, nr DESC LIMIT :limit;"; $query .= " ORDER BY datum DESC, nr DESC LIMIT :limit;";
//echo( $query );
$pdoStatementForQuerryingNews = $aMysqlConn->prepare( $pdoStatementForQuerryingNews = $aMysqlConn->prepare(
$query $query
); );
} }
if( is_positive_integer($optionsArray['jahr']) ) $pdoStatementForQuerryingNews->bindParam(':limit', intval($optionsArray['limit']), PDO::PARAM_INT);
$pdoStatementForQuerryingNews->bindParam(':jahr', intval($optionsArray['jahr']), PDO::PARAM_INT); // $pdoStatementForQuerryingNews->bindParam(':jahr', intval($optionsArray['jahr']), PDO::PARAM_INT);
else
$pdoStatementForQuerryingNews->bindParam(':limit', intval($optionsArray['limit']), PDO::PARAM_INT);
$pdoStatementForQuerryingNews->execute(); $pdoStatementForQuerryingNews->execute();
$ret = $pdoStatementForQuerryingNews->fetchAll(PDO::FETCH_ASSOC); $ret = $pdoStatementForQuerryingNews->fetchAll(PDO::FETCH_ASSOC);
@@ -90,9 +90,13 @@ $options = getKeyValueArray($someOptions);
$retHtml .= "</div>"; $retHtml .= "</div>";
$retHtml .= "<div class=\"newsBody\">"; $retHtml .= "<div class=\"newsBody\">";
// phpMyAdmin fügte manchmal die falschen Zeilenenden ein
$aNews['nachricht'] = str_replace("\r\n", "\n", $aNews['nachricht']); $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 = new DOMDocument();
$domDoc->loadHTML( mb_convert_encoding($aNews['nachricht'], 'HTML-ENTITIES', "UTF-8") ); $domDoc->loadHTML( mb_convert_encoding($aNews['nachricht'], 'HTML-ENTITIES', "UTF-8") );
foreach($domDoc->getElementsByTagName('a') as $anchor){ foreach($domDoc->getElementsByTagName('a') as $anchor){