svn: /pear2/sandbox/pear2.php.net/trunk/ src/pear2web/Router.php www/index.php www/templates/pear2/html/Main.tpl.php

[email protected] (Brett Bieber)
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
saltybeagle                              Fri, 11 Jun 2010 14:17:50 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=300386

Log:
Change routing to get querystring params out of the URLs.

Changed paths:
    U   pear2/sandbox/pear2.php.net/trunk/src/pear2web/Router.php
    U   pear2/sandbox/pear2.php.net/trunk/www/index.php
    U   pear2/sandbox/pear2.php.net/trunk/www/templates/pear2/html/Main.tpl.php

Modified: pear2/sandbox/pear2.php.net/trunk/src/pear2web/Router.php
===================================================================
--- pear2/sandbox/pear2.php.net/trunk/src/pear2web/Router.php	2010-06-11 14:04:57 UTC (rev 300385)
+++ pear2/sandbox/pear2.php.net/trunk/src/pear2web/Router.php	2010-06-11 14:17:50 UTC (rev 300386)
@@ -8,17 +8,27 @@
             $requestURI = substr($requestURI, 0, strlen($_SERVER['QUERY_STRING'])*-1-1);
         }

-        $base = preg_quote(\PEAR2\SimpleChannelFrontend\Main::getURL(), '/');
+        $base   = \PEAR2\SimpleChannelFrontend\Main::getURL();
+        $q_base = preg_quote($base, '/');

         $options = array();

         switch(true) {
-            case ($requestURI == '/'):
+            case ($requestURI == $base):
                 // Short circuit
-                $options['view'] = 'News';
+                $options['view'] = 'news';
                 break;
+            case ($requestURI == $base . 'categories/'):
+                $options['view'] = 'categories';
+                break;
+            case ($requestURI == $base . 'packages/'):
+                $options['view'] = 'packages';
+                break;
+            case ($requestURI == $base . 'support/'):
+                $options['view'] = 'support';
+                break;

-            case preg_match('/\/(?<package>[0-9a-z_]+)(-(?<version>[0-9ab.]+))?$/i',
+            case preg_match('/'.$q_base.'(?<package>[0-9a-z_]+)(-(?<version>[0-9ab.]+))?$/i',
                     $requestURI, $matches):

                 // Viewing an individual package

Modified: pear2/sandbox/pear2.php.net/trunk/www/index.php
===================================================================
--- pear2/sandbox/pear2.php.net/trunk/www/index.php	2010-06-11 14:04:57 UTC (rev 300385)
+++ pear2/sandbox/pear2.php.net/trunk/www/index.php	2010-06-11 14:17:50 UTC (rev 300386)
@@ -2,12 +2,12 @@
 require_once dirname(__FILE__).'/../config.inc.php';
 require_once dirname(__FILE__).'/../src/pear2web/Router.php';

-$options = $_GET;
-
 $channel = new \PEAR2\Pyrus\ChannelFile(__DIR__ . '/channel.xml');

-$frontend = new PEAR2\SimpleChannelFrontend\Main($channel, pear2web\Router::getRoute($_SERVER['REQUEST_URI']) + $_GET);
+$options = $_GET + pear2web\Router::getRoute($_SERVER['REQUEST_URI']);

+$frontend = new PEAR2\SimpleChannelFrontend\Main($channel, $options);
+
 $savant = new PEAR2\Templates\Savant\Main();
 $savant->setClassToTemplateMapper(new PEAR2\SimpleChannelFrontend\TemplateMapper);
 $savant->setTemplatePath(array(__DIR__ . '/templates/default/html', __DIR__ . '/templates/pear2/html'));
@@ -21,4 +21,4 @@
 $savant->setEscape('htmlspecialchars');
 $savant->addFilters(array($frontend, 'postRender'));
 echo $savant->render($frontend);
-?>
+

Modified: pear2/sandbox/pear2.php.net/trunk/www/templates/pear2/html/Main.tpl.php
===================================================================
--- pear2/sandbox/pear2.php.net/trunk/www/templates/pear2/html/Main.tpl.php	2010-06-11 14:04:57 UTC (rev 300385)
+++ pear2/sandbox/pear2.php.net/trunk/www/templates/pear2/html/Main.tpl.php	2010-06-11 14:17:50 UTC (rev 300386)
@@ -24,10 +24,10 @@
             <h1><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>"><img src="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>templates/pear2/html/css/img/logo.png" alt="PEAR" /><span>PHP Extension and Application Repository</span></a></h1>
             <div id="nav">
                 <ul id="navbar">
-                    <li><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL('PEAR2\SimpleChannelFrontend\News'); ?>">Home</a></li>
-                    <li><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL('PEAR2\SimpleChannelFrontend\PackageList'); ?>">Packages</a></li>
-                    <li><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL('PEAR2\SimpleChannelFrontend\Categories'); ?>">Categories</a></li>
-                    <li><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL('PEAR2\SimpleChannelFrontend\Support'); ?>">Support</a></li>
+                    <li><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>">Home</a></li>
+                    <li><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>packages/">Packages</a></li>
+                    <li><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>categories/">Categories</a></li>
+                    <li><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>support/">Support</a></li>
                 </ul>
             </div>

@@ -82,16 +82,16 @@

         <div id="footer-left">
             <ul class="footer-menu">
-                <li class="header"><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL('PEAR2\SimpleChannelFrontend\News'); ?>">Home</a></li>
+                <li class="header"><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>">Home</a></li>
             </ul>
             <ul class="footer-menu">
-                <li class="header"><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL('PEAR2\SimpleChannelFrontend\PackageList'); ?>">Packages</a></li>
+                <li class="header"><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>packages/">Packages</a></li>
             </ul>
             <ul class="footer-menu">
-                <li class="header"><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL('PEAR2\SimpleChannelFrontend\Categories'); ?>">Categories</a></li>
+                <li class="header"><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>categories/">Categories</a></li>
             </ul>
             <ul class="footer-menu footer-menu-last">
-                <li class="header"><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL('PEAR2\SimpleChannelFrontend\Support'); ?>">Support</a></li>
+                <li class="header"><a href="<?php echo PEAR2\SimpleChannelFrontend\Main::getURL(); ?>support/">Support</a></li>
             </ul>
             <p class="note">
             Copyright © 2001-2010 The PEAR Group, all rights reserved. Bandwidth and
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.