com web/php: Incorporated new introduction text from `pregen_news.inc` file. Also improved the N ewsItem class.: Entity/NewsItem.php Gateway/NewsFil
eSystemGateway.php View/HomepageNewsView.php

From: Date: Thu, 05 Jul 2012 20:43:00 +0000
Subject: com web/php: Incorporated new introduction text from `pregen_news.inc` file. Also improved the N ewsItem class.: Entity/NewsItem.php Gateway/NewsFil
eSystemGateway.php View/HomepageNewsView.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-13874@lists.php.net to get a copy of this message
Commit: 09b0ec51f757f64992522bc845932d17361d0d51 Author: Levi Morrison <levim@php.net> Thu, 5 Jul 2012 14:43:00 -0600 Parents: 188838f661c351464461df7e7de492d07cfce914 Branches: master Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=09b0ec51f757f64992522bc845932d17361d0d51 Log: Incorporated new introduction text from pregen_news.inc file. Also improved the NewsItem class. Changed paths: M Entity/NewsItem.php M Gateway/NewsFileSystemGateway.php M View/HomepageNewsView.php Diff: diff --git a/Entity/NewsItem.php b/Entity/NewsItem.php index 7120c15..6f1db10 100644 --- a/Entity/NewsItem.php +++ b/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 @@ 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; + } + } diff --git a/Gateway/NewsFileSystemGateway.php b/Gateway/NewsFileSystemGateway.php index 5739b7c..dbe4ae5 100644 --- a/Gateway/NewsFileSystemGateway.php +++ b/Gateway/NewsFileSystemGateway.php @@ -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'] ); } diff --git a/View/HomepageNewsView.php b/View/HomepageNewsView.php index bc56a12..989ba7b 100644 --- a/View/HomepageNewsView.php +++ b/View/HomepageNewsView.php @@ -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>&hellip; 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";

« previous php.webmaster (#13874) next »