com web/master: Generate a shorter news intro for long entries. Originally by Levi in phpweb: scripts/pregen_news
| From: | Hannes Magnusson | Date: | Thu, 05 Jul 2012 19:38:33 +0000 |
| Subject: | com web/master: Generate a shorter news intro for long entries. Originally by Levi in phpweb: scripts/pregen_news | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-13869@lists.php.net to get a copy of this message | ||
Commit: e12bc0e6ba2e72391becf2de0abe1bfc2645f964
Author: Hannes Magnusson <bjori@10gen.com> Thu, 5 Jul 2012 20:38:33 +0100
Parents: b71d6129492b0f9def108937132b82db4d1950a3
Branches: master
Link: http://git.php.net/?p=web/master.git;a=commitdiff;h=e12bc0e6ba2e72391becf2de0abe1bfc2645f964
Log:
Generate a shorter news intro for long entries.
Originally by Levi in phpweb
Changed paths:
M scripts/pregen_news
Diff:
diff --git a/scripts/pregen_news b/scripts/pregen_news
index 545ecd7..6fd0607 100644
--- a/scripts/pregen_news
+++ b/scripts/pregen_news
@@ -105,6 +105,33 @@ function format_atom_entry($r) {
} else {
$retval[$name] = $r->readString();
}
+
+ $dom = new DOMDocument();
+ @$dom->loadHTML($retval[$name]);
+
+ $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) {
+ $permanentLink = get_link($retval, "alternate");
+ $content .= "<p class='fullArticleLink'><a
href='$permanentLink' class>… read full article</a></p>";
+ }
+
+ $content .= '</div>';
+ } else {
+ $content = $retval[$name];
+ }
+ $retval["intro"] = $content;
break;
}
} elseif ($r->namespaceURI === XMLNS_PHP) {
@@ -141,6 +168,15 @@ function format_attributes($r) {
return $retval;
} // }}}
+function get_link($data, $rel = "alternate") {
+ foreach($data["link"] as $link) {
+ if ($link["rel"] == $rel) {
+ return $link["href"];
+ }
+ }
+ return "";
+}
+
function legacy_rss($atom, $newsDest, $confDest) {
$sxe = new SimpleXMLElement($atom, $GLOBALS["XML_OPTIONS"], true);
$CONF = $CONF_ITEMS = $NEWS = $NEWS_ITEMS= "";