Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Incorporated new introduction text from `pregen_news.inc` file. Also …

…improved the NewsItem class.
  • Loading branch information...
commit 09b0ec51f757f64992522bc845932d17361d0d51 1 parent 188838f
@morrisonlevi morrisonlevi authored
View
32 Entity/NewsItem.php
@@ -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 @@ public function getContent() {
}
/**
- * @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 @@ public function hasCategory($category) {
return false;
}
+ public function getIntroduction() {
+ return $this->intro;
+ }
+
}
View
3  Gateway/NewsFileSystemGateway.php
@@ -28,7 +28,8 @@ public function __construct() {
$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']
);
}
View
31 View/HomepageNewsView.php
@@ -25,14 +25,12 @@ public function render() {
* @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 @@ public function render() {
}
}
- $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>&hellip; read full article</a></p>";
- }
-
- $content .= '</div>';
- } else {
- $content = $contentRaw;
- }
+ $content = $article->getIntroduction();
$image = "";
$newsImage = $article->getNewsImage();
@@ -72,8 +47,6 @@ public function render() {
$image = "<a href=\"{$newsImage["link"]}\">" . $this->renderImage($newsImage) . "</a>";
}
- $itemCategories = $article->getCategories();
-
$event = '';
if ($article->hasCategory('conferences') || $article->hasCategory('cfp')) {
$event = " vevent";
Please sign in to comment.
Something went wrong with that request. Please try again.