mirror of
https://github.com/php/web-php.git
synced 2026-03-23 23:02:13 +01:00
Incorporated new introduction text from pregen_news.inc file. Also improved the NewsItem class.
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
class NewsItem {
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
protected $permanentUrl;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -42,26 +42,33 @@ class NewsItem {
|
||||
*/
|
||||
protected $newsImage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $intro = '';
|
||||
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param int $id
|
||||
* @param string $permanentUrl
|
||||
* @param string $published
|
||||
* @param string $updated
|
||||
* @param array $category
|
||||
* @param array $link
|
||||
* @param string $content
|
||||
* @param string $newsImage
|
||||
* @param string $intro
|
||||
*/
|
||||
function __construct($title, $id, $published, $updated, $category, $link, $content, $newsImage = NULL) {
|
||||
function __construct($title, $permanentUrl, $published, $updated, $category, $link, $content, $newsImage = NULL, $intro = '') {
|
||||
$this->title = $title;
|
||||
$this->id = $id;
|
||||
$this->permanentUrl = $permanentUrl;
|
||||
$this->published = $published;
|
||||
$this->updated = new DateTime($updated);
|
||||
$this->category = $category;
|
||||
$this->link = $link;
|
||||
$this->content = $content;
|
||||
$this->newsImage = $newsImage;
|
||||
$this->intro = $intro;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,10 +86,17 @@ class NewsItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return string
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
return parse_url($this->getPermanentUrl(), PHP_URL_FRAGMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPermanentUrl() {
|
||||
return $this->permanentUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,4 +151,8 @@ class NewsItem {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getIntroduction() {
|
||||
return $this->intro;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ class NewsFileSystemGateway implements NewsGateway {
|
||||
$article['category'],
|
||||
$article['link'],
|
||||
$article['content'],
|
||||
isset($article['newsImage']) ? $article['newsImage'] : NULL
|
||||
isset($article['newsImage']) ? $article['newsImage'] : NULL,
|
||||
isset($article['intro']) ? $article['intro'] : $article['content']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,14 +25,12 @@ class HomepageNewsView {
|
||||
* @var NewsItem $article
|
||||
*/
|
||||
|
||||
$id = parse_url($article->getId(), PHP_URL_FRAGMENT);
|
||||
$id = $article->getId();
|
||||
$title = $article->getTitle();
|
||||
|
||||
$publishedDate = $article->getPublishedString();
|
||||
$newsDate = $article->getPublishedDate()->format('d-M-Y');
|
||||
|
||||
$contentRaw = $article->getContent();
|
||||
|
||||
$permanentLink = "#" .$id;
|
||||
foreach($article->getLink() as $link) {
|
||||
if ($link["rel"] === "via") {
|
||||
@@ -41,30 +39,7 @@ class HomepageNewsView {
|
||||
}
|
||||
}
|
||||
|
||||
$dom = new DOMDocument();
|
||||
@$dom->loadHTML($contentRaw);
|
||||
|
||||
$xpath = new DomXPath($dom);
|
||||
$nodes = $xpath->query('//body/div/*');
|
||||
|
||||
if ($nodes !== FALSE) {
|
||||
$content = '<div>';
|
||||
|
||||
$count = 0;
|
||||
foreach ($nodes as $node) {
|
||||
if ($count++ < 2) {
|
||||
$content .= $dom->saveXML($node);
|
||||
}
|
||||
}
|
||||
|
||||
if ($count > 2) {
|
||||
$content .= "<p class='fullArticleLink'><a href='$permanentLink' class>… read full article</a></p>";
|
||||
}
|
||||
|
||||
$content .= '</div>';
|
||||
} else {
|
||||
$content = $contentRaw;
|
||||
}
|
||||
$content = $article->getIntroduction();
|
||||
|
||||
$image = "";
|
||||
$newsImage = $article->getNewsImage();
|
||||
@@ -72,8 +47,6 @@ class HomepageNewsView {
|
||||
$image = "<a href=\"{$newsImage["link"]}\">" . $this->renderImage($newsImage) . "</a>";
|
||||
}
|
||||
|
||||
$itemCategories = $article->getCategories();
|
||||
|
||||
$event = '';
|
||||
if ($article->hasCategory('conferences') || $article->hasCategory('cfp')) {
|
||||
$event = " vevent";
|
||||
|
||||
Reference in New Issue
Block a user