svn: /pear2/sandbox/Pyrus_WebFrontend/trunk/ src/pear2/Pyrus/WebFrontend/Controller.php src/pear2/Pyrus/WebFrontend/DiscoverChannel.php
www/templates/WebFrontend/Controller.tpl.php www/templates/WebFrontend/DiscoverChannel.tpl.php
| From: | Brett Bieber | Date: | Tue, 23 Mar 2010 14:47:07 +0000 |
| Subject: | svn: /pear2/sandbox/Pyrus_WebFrontend/trunk/ src/pear2/Pyrus/WebFrontend/Controller.php src/pear2/Pyrus/WebFrontend/DiscoverChannel.php www/templates/WebFrontend/Controller.tpl.php www/templates/WebFrontend/DiscoverChannel.tpl.php |
||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-9323@lists.php.net to get a copy of this message | ||
saltybeagle Tue, 23 Mar 2010 14:47:07 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=296676
Log:
Add discover channel command.
Changed paths:
U pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/Controller.php
A pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/DiscoverChannel.php
U pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/Controller.tpl.php
A pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/DiscoverChannel.tpl.php
Modified: pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/Controller.php
===================================================================
--- pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/Controller.php 2010-03-23
14:28:02 UTC (rev 296675)
+++ pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/Controller.php 2010-03-23
14:47:07 UTC (rev 296676)
@@ -28,6 +28,7 @@
{
public $view_map = array(
'index' => 'pear2\Pyrus\WebFrontend\Index',
+ 'discoverchannel' => 'pear2\Pyrus\WebFrontend\DiscoverChannel',
'list_channels' => 'pear2\Pyrus\WebFrontend\ListChannels',
'list_packages' => 'pear2\Pyrus\WebFrontend\ListPackages',
'install' => 'pear2\Pyrus\WebFrontend\InstallPackage'
Added: pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/DiscoverChannel.php
===================================================================
--- pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/DiscoverChannel.php
(rev 0)
+++ pear2/sandbox/Pyrus_WebFrontend/trunk/src/pear2/Pyrus/WebFrontend/DiscoverChannel.php 2010-03-23
14:47:07 UTC (rev 296676)
@@ -0,0 +1,43 @@
+<?php
+namespace pear2\Pyrus\WebFrontend;
+class DiscoverChannel
+{
+ function __construct($options = array())
+ {
+ if (isset($_POST)) {
+ $this->handlePost();
+ }
+ }
+
+ function handlePost()
+ {
+ if (isset($_POST['_type'], $_POST['channel'])) {
+ $chan = 'https://' . $_POST['channel']
. '/channel.xml';
+ try {
+ $response = \pear2\Pyrus\Main::download($chan);
+ if ($response->code != 200) {
+ throw new \pear2\Pyrus\Exception('Download of channel.xml failed');
+ }
+ $this->_addChannelXML($response->body);
+ } catch (\Exception $e) {
+ try {
+ $chan = 'http://' .
$_POST['channel'] . '/channel.xml';
+ $response = \pear2\Pyrus\Main::download($chan);
+ if ($response->code != 200) {
+ throw new \pear2\Pyrus\Exception('Download of channel.xml
failed');
+ }
+ $this->_addChannelXML($response->body);
+ } catch (\Exception $e) {
+ // failed, re-throw original error
+ throw new \Exception('Could not discover the channel
'.$_POST['channel'], $e);
+ }
+ }
+ }
+ }
+
+ protected function _addChannelXML($xml)
+ {
+ $chan = new \pear2\Pyrus\Channel(new \pear2\Pyrus\ChannelFile($xml, true));
+ \pear2\Pyrus\Config::current()->channelregistry->add($chan);
+ }
+}
\ No newline at end of file
Modified: pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/Controller.tpl.php
===================================================================
--- pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/Controller.tpl.php 2010-03-23
14:28:02 UTC (rev 296675)
+++ pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/Controller.tpl.php 2010-03-23
14:47:07 UTC (rev 296676)
@@ -8,6 +8,7 @@
<li><a href="?view=list_packages">List Packages</a></li>
<li><a href="?view=list_channels">List Channels</a></li>
<li><a href="?view=install">Install/Upgrade</a></li>
+ <li><a href="?view=discoverchannel">Add Channel</a></li>
</ul>
<?php echo $savant->render($context->actionable); ?>
</body>
\ No newline at end of file
Added: pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/DiscoverChannel.tpl.php
===================================================================
--- pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/DiscoverChannel.tpl.php
(rev 0)
+++
pear2/sandbox/Pyrus_WebFrontend/trunk/www/templates/WebFrontend/DiscoverChannel.tpl.php 2010-03-23
14:47:07 UTC (rev 296676)
@@ -0,0 +1,6 @@
+<h2>Add Channel</h2>
+<form method="post" action="?view=discoverchannel">
+ <input type="hidden" name="_type" value="channel" />
+ <label>Channel Name (eg pear.unl.edu):</label><input type="text"
name="channel" />
+ <input type="submit" value="submit" />
+</form>
\ No newline at end of file