Change the links in our RSS feed to the entry it self

From: Date: Sat, 10 Feb 2007 20:40:56 +0000
Subject: Change the links in our RSS feed to the entry it self
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-34207@lists.php.net to get a copy of this message
Hi all I'd like to change the links in our RSS feeds to point the entry on php.net rather then php.net[/conferences] or other url at "seemingly random". See attached patches for the RSS parser and phpweb.

Index: scripts/rss_parser =================================================================== RCS file: /repository/php-master-web/scripts/rss_parser,v retrieving revision 1.16 diff -u -r1.16 rss_parser --- scripts/rss_parser 8 Feb 2007 22:36:06 -0000 1.16 +++ scripts/rss_parser 10 Feb 2007 20:31:54 -0000 @@ -18,9 +18,11 @@ } // Try to find a link in the text with any the used linking methods -function scanLinks($text) { +function scanLinks($text, $rootLink) { - if (preg_match('/<\?php\s+print_link\s*\("([^"]+)",\s*"[^"]+"\);\s*\?>/', $text, $matches)) { + if (preg_match('/<a\s+name="([^"]*)">/', $text, $matches)) { + $link = "#" .$matches[1]; + } elseif (preg_match('/<\?php\s+print_link\s*\("([^"]+)",\s*"[^"]+"\);\s*\?>/', $text, $matches)) { $link = $matches[1]; } elseif (preg_match('/<\?php\s+print_link\s*\(\'([^\']+)\',\s*\'[^\']+\'\);\s*\?>/', $text, $matches)) { $link = $matches[1]; @@ -32,7 +34,8 @@ // Make sure it is a full URL if (!preg_match('/^http:/', $link)) { - $link = ($link{0} != '/') ? "http://www.php.net/$link" : "http://www.php.net$link"; + $rootLink = rtrim($rootLink, "/"); + $link = ($link{0} != '/') ? "$rootLink/$link" : "$rootLink$link"; } return $link; @@ -62,7 +65,7 @@ } // Parse the index file searching for news item information -function ParseNews ($index_page = "") { +function ParseNews ($index_page = "", $aboutLink) { // Remove commented items $index_page = preg_replace("/<!--[\w\W]*?-->/", "", $index_page); @@ -103,7 +106,7 @@ #DEBUG# print "<p>Info: New Headline: $headlineid<br />"; // End of headlines reached - } elseif (preg_match('@<a href="/news-\d+.php">News Archive</a>@', $line)) { + } elseif (preg_match('@<a href="/news-\d+.php">News Archive</a>@', $line) || strpos($line, "// NO MORE NEWS TO PARSE") === 0) { array_pop($headlines); break; @@ -137,7 +140,7 @@ foreach ($headlines as $num => $headline) { // The first link found is THE link for the news item - $headlines[$num]['link'] = scanLinks($headline['text']); + $headlines[$num]['link'] = scanLinks($headline['text'], $aboutLink); // And the text needs to be cleaned up $headlines[$num]['text'] = ProcessText($headline['text']); @@ -192,7 +195,7 @@ $homepage = getData("$root/index.php"); // This returns a data structure containing all the news items found -$hlines = ParseNews($homepage); +$hlines = ParseNews($homepage, $aboutLink); // Start with an empty RSS string $RSS = ''; Index: index.php =================================================================== RCS file: /repository/phpweb/index.php,v retrieving revision 1.857 diff -u -r1.857 index.php --- index.php 9 Feb 2007 09:07:54 -0000 1.857 +++ index.php 10 Feb 2007 20:32:56 -0000 @@ -146,6 +146,7 @@ // DO NOT REMOVE THIS COMMENT (the RSS parser is dependant on it) ?> +<a name="4"></a> <h1>PHP 5.2.1 Released</h1> <p> <span class="newsdate">[08-Feb-2007]</span> @@ -197,7 +198,7 @@ <hr /> - +<a name="3"></a> <h1>The front page has changed</h1> <p> <span class="newsdate">[08-Feb-2007]</span> @@ -209,6 +210,7 @@ <hr /> +<a name="2"></a> <?php news_image('http://php.net/manual/en/','php-logo.gif','The PHP Manual'); ?> <h1>PHP Manual Updates</h1> <p> @@ -233,6 +235,7 @@ <hr /> +<a name="1"></a> <h1>PHP 5.2.0 Released</h1> <p> <span class="newsdate">[02-Nov-2006]</span> Index: conferences/index.php =================================================================== RCS file: /repository/phpweb/conferences/index.php,v retrieving revision 1.5 diff -u -r1.5 index.php --- conferences/index.php 8 Feb 2007 23:57:31 -0000 1.5 +++ conferences/index.php 10 Feb 2007 20:32:56 -0000 @@ -18,6 +18,7 @@ // DO NOT REMOVE THIS COMMENT (the RSS parser is dependant on it) ?> +<a name="6"></a> <?php news_image("http://conf.phpquebec.com/en/conf2007/", "conference_php_quebec.gif ", "PHP Québec conference"); ?> <h1>PHP Québec conference 2007</h1> <p> @@ -43,6 +44,7 @@ <hr /> +<a name="5"></a> <?php news_image("http://conferences.oreillynet.com/os2007/", "os2007.gif", "OSCON Open Source Convention"); ?> <h1> O'Reilly OSCON call for papers</h1> <p> @@ -53,6 +55,7 @@ <hr /> +<a name="4"></a> <?php news_image("http://phpconference.com/", "intcon2007spring.png", "International PHP Conference 2007 Spring Edition"); ?> <h1>International PHP Conference 2007 Spring Edition : Call for Paper</h1> <p> @@ -71,6 +74,8 @@ </p> <hr /> + +<a name="3"></a> <?php news_image("http://www.phpconference.co.uk/", "phplondon2007.png", "PHP London 2007"); ?> <h1>PHP London 2007</h1> <p> @@ -79,6 +84,8 @@ </p> <hr /> + +<a name="2"></a> <?php news_image("http://www.phparch.com/tek", "phptek2007.png", "php|tek 2007"); ?> <h1>php|tek 2007</h1> <p> @@ -91,6 +98,7 @@ <hr /> +<a name="1"></a> <?php news_image("http://vancouver.php.net/", "vancouver_conference_2007.gif", "PHP Vancouver 2007"); ?> <h1>Vancouver PHP Conference</h1> <p> @@ -108,6 +116,7 @@ <hr /> - -<?php site_footer(); +<?php +// NO MORE NEWS TO PARSE +site_footer();
« previous php.mirrors (#34207) next »