svn: /pear/pearweb/trunk/public_html/channels/ add.php
[email protected] ("Daniel O'Connor") Sat, 09 Apr 2011 13:10:25 +0000
| Newsgroups | php.pear.cvs,php.pear.core |
|---|---|
| Message-ID | <[email protected]> |
clockwerx Sat, 09 Apr 2011 13:10:25 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=310085
Log:
Update to HTML_QuickForm2, html5 controls
Changed paths:
U pear/pearweb/trunk/public_html/channels/add.php
svn-diffs-310085.txt
(text/x-diff, 15.2 KB)
Modified: pear/pearweb/trunk/public_html/channels/add.php
===================================================================
--- pear/pearweb/trunk/public_html/channels/add.php 2011-04-09 13:04:20 UTC (rev 310084)
+++ pear/pearweb/trunk/public_html/channels/add.php 2011-04-09 13:10:25 UTC (rev 310085)
@@ -19,13 +19,36 @@
*/
response_header("Channels :: Add");
-require_once "HTML/QuickForm.php";
+require_once "HTML/QuickForm2.php";
require_once "HTTP/Request2.php";
require_once "Net/URL2.php";
require_once "Damblan/Log.php";
require_once "Damblan/Log/Mail.php";
+require_once 'HTML/QuickForm2/Renderer.php';
+require_once 'HTML/QuickForm2/Element/Input.php';
+/** @todo Shift ! */
+if (!class_exists('HTML_QuickForm2_Element_InputUrl')) {
+ class HTML_QuickForm2_Element_InputUrl extends HTML_QuickForm2_Element_Input
+ {
+ protected $attributes = array('type' => 'url');
+ }
+
+ HTML_QuickForm2_Factory::registerElement('url', 'HTML_QuickForm2_Element_InputUrl');
+}
+
+
+/** @todo Shift ! */
+if (!class_exists('HTML_QuickForm2_Element_InputEmai')) {
+ class HTML_QuickForm2_Element_InputEmail extends HTML_QuickForm2_Element_Input
+ {
+ protected $attributes = array('type' => 'email');
+ }
+
+ HTML_QuickForm2_Factory::registerElement('email', 'HTML_QuickForm2_Element_InputEmail');
+}
+
$tabs = array("List" => array("url" => "/channels/index.php",
"title" => "List Sites."),
"Add Site" => array("url" => "/channels/add.php",
@@ -45,142 +68,154 @@
staff may reject your submission if they do not consider it appropriate.</p>
<?php
-$form = new HTML_QuickForm("submitForm");
+$form = new HTML_QuickForm2("submitForm");
$form->removeAttribute('name');
if (isset($auth_user)) {
- $form->setDefaults(array("name" => $auth_user->name,
- "email" => $auth_user->email));
+ $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array("name" => $auth_user->name,
+ "email" => $auth_user->email)));
}
-$form->addElement("text", "name", "Your name:",
- array("size" => 30));
-$form->addElement("text", "email", "Your email address:",
- array("size" => 30));
-$form->addElement("text", "project[name]", "Project Name:",
- array("size" => 30));
-$form->addElement("text", "project[link]", "Project Link:",
- array("size" => 30));
-$form->addElement("submit", null, "Send");
+$name = $form->addElement("text", "name", array('required' => 'required', 'placeholder' => 'John Doe'))
+ ->setLabel("Your name")
+ ->addFilter("htmlspecialchars")
+ ->addRule('required', "Please enter your name");
-$form->addRule("name", "Please enter your name", "required", null, "client");
-$form->applyFilter("name", "htmlspecialchars");
-$form->addRule("email", "Please enter your email address", "required", null, "client");
-$form->addRule("email", "Please enter a valid email address", "email", null, "client");
-$form->applyFilter("email", "htmlspecialchars");
-$form->addRule("project[name]", "Please enter the project name", "required", null, "client");
-$form->applyFilter("project[name]", "htmlspecialchars");
-$form->addRule("project[link]", "Please enter the project link", "required", null, "client");
-$form->addRule("project[link]", "Please supply a valid project link", "regex", "/^http(s?):\\/\\/(.+)/", "client");
-$form->applyFilter("project[link]", "htmlspecialchars");
+$email = $form->addElement("email", "email", array('required' => 'required', '[email protected]'))
+ ->setLabel("Email")
+ ->addFilter("htmlspecialchars");
+$email->addRule('required', "Please enter your email address");
+$email->addRule('callback', '', array('callback' => 'filter_var',
+ 'arguments' => array(FILTER_VALIDATE_EMAIL)));
+
+$project_name = $form->addElement("text", "project[name]", array('required' => 'required', 'placeholder' => 'PHPUnit'))
+ ->setLabel("Project Name")
+ ->addFilter("htmlspecialchars")
+ ->addRule('required', "Please enter your project name");
+
+$link = $form->addElement("url", "project[link]", array('required' => 'required', 'placeholder' => 'http://pear.phpunit.de/'));
+$link->setLabel("Link");
+$link->addFilter("htmlspecialchars");
+$link->addRule('required', "Please enter your project link");
+
+$form->addElement("submit");
+
if ($form->validate()) {
- $url =& new Net_URL2($form->exportValue("project[link]"));
+ $url = new Net_URL2($link->getValue());
- $req =& new HTTP_Request2;
+ try {
+ $req = new HTTP_Request2;
- $req->setURL($url->getScheme() . "://" . $url->getHost() . ":" . $url->getPort() . "/channel.xml");
- $response = $req->send();
- if ($response->getStatus() != 200) {
- echo "<div class=\"errors\">The submitted URL does not ";
- echo "appear to point to a valid channel site. You will ";
- echo "have to make sure that <tt>/channel.xml</tt> at least ";
- echo "exists and is valid. If you think that this mechanism does not work ";
- echo "properly, please drop a mail to the ";
- echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
- echo "</div>";
+ $req->setURL($url->getScheme() . "://" . $url->getHost() . ":" . $url->getPort() . "/channel.xml");
+ $response = $req->send();
+ if ($response->getStatus() != 200) {
+ echo "<div class=\"errors\">The submitted URL does not ";
+ echo "appear to point to a valid channel site. You will ";
+ echo "have to make sure that <tt>/channel.xml</tt> at least ";
+ echo "exists and is valid. If you think that this mechanism does not work ";
+ echo "properly, please drop a mail to the ";
+ echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
+ echo "</div>";
- $form->display();
- } elseif (!$response->getBody()) {
- // channel.xml is empty - spam spam spam
- echo "<div class=\"errors\">The submitted URL does not ";
- echo "appear to point to a valid channel site. You will ";
- echo "have to make sure that <tt>/channel.xml</tt> at least ";
- echo "exists and is valid. If you think that this mechanism does not work ";
- echo "properly, please drop a mail to the ";
- echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
- echo "</div>";
+ echo $form;
+ } elseif (!$response->getBody()) {
+ // channel.xml is empty - spam spam spam
+ echo "<div class=\"errors\">The submitted URL does not ";
+ echo "appear to point to a valid channel site. You will ";
+ echo "have to make sure that <tt>/channel.xml</tt> at least ";
+ echo "exists and is valid. If you think that this mechanism does not work ";
+ echo "properly, please drop a mail to the ";
+ echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
+ echo "</div>";
- $form->display();
- } elseif (strlen($response->getBody()) > 100000) {
- // channel.xml is huge - possible DoS attack
- echo "<div class=\"errors\">The submitted URL does not ";
- echo "appear to point to a valid channel site. You will ";
- echo "have to make sure that <tt>/channel.xml</tt> at least ";
- echo "exists and is not huge. If you think that this mechanism does not work ";
- echo "properly, please drop a mail to the ";
- echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
- echo "</div>";
+ echo $form;
+ } elseif (strlen($response->getBody()) > 100000) {
+ // channel.xml is huge - possible DoS attack
+ echo "<div class=\"errors\">The submitted URL does not ";
+ echo "appear to point to a valid channel site. You will ";
+ echo "have to make sure that <tt>/channel.xml</tt> at least ";
+ echo "exists and is not huge. If you think that this mechanism does not work ";
+ echo "properly, please drop a mail to the ";
+ echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
+ echo "</div>";
- $form->display();
- } else {
- do {
- // poor man's try/catch
- require_once 'PEAR/ChannelFile.php';
- $chan = new PEAR_ChannelFile;
- if (!$chan->fromXmlString($response->getBody())) {
- // channel.xml is invalid xml - spam spam spam
- echo "<div class=\"errors\">The submitted URL does not ";
- echo "appear to point to a valid channel site. You will ";
- echo "have to make sure that <tt>/channel.xml</tt> at least ";
- echo "exists and is valid. If you think that this mechanism does not work ";
- echo "properly, please drop a mail to the ";
- echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
- echo "</div>";
+ echo $form;
+ } else {
+ do {
+ // poor man's try/catch
+ require_once 'PEAR/ChannelFile.php';
+ $chan = new PEAR_ChannelFile;
+ if (!$chan->fromXmlString($response->getBody())) {
+ // channel.xml is invalid xml - spam spam spam
+ echo "<div class=\"errors\">The submitted URL does not ";
+ echo "appear to point to a valid channel site. You will ";
+ echo "have to make sure that <tt>/channel.xml</tt> at least ";
+ echo "exists and is valid. If you think that this mechanism does not work ";
+ echo "properly, please drop a mail to the ";
+ echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
+ echo "</div>";
- $form->display();
- break;
- }
- if (!$chan->validate()) {
- // channel.xml is invalid channelfile xml - spam spam spam
- echo "<div class=\"errors\">The submitted URL does not ";
- echo "appear to point to a valid channel site. You will ";
- echo "have to make sure that <tt>/channel.xml</tt> at least ";
- echo "exists and is valid. If you think that this mechanism does not work ";
- echo "properly, please drop a mail to the ";
- echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
- echo "</div>";
+ echo $form;
+ break;
+ }
+ if (!$chan->validate()) {
+ // channel.xml is invalid channelfile xml - spam spam spam
+ echo "<div class=\"errors\">The submitted URL does not ";
+ echo "appear to point to a valid channel site. You will ";
+ echo "have to make sure that <tt>/channel.xml</tt> at least ";
+ echo "exists and is valid. If you think that this mechanism does not work ";
+ echo "properly, please drop a mail to the ";
+ echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
+ echo "</div>";
- $form->display();
- break;
- }
- if ($url->getHost() != $chan->getServer()) {
- // channel.xml refers to different site - spam spam spam
- echo "<div class=\"errors\">The submitted URL does not ";
- echo "appear to point to a valid channel site. You will ";
- echo "have to make sure that <tt>/channel.xml</tt> at least ";
- echo "exists and is valid. In addition, it must refer to ";
- echo "your channel. If you think that this mechanism does not work ";
- echo "properly, please drop a mail to the ";
- echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
- echo "</div>";
+ echo $form;
+ break;
+ }
+ if ($url->getHost() != $chan->getServer()) {
+ // channel.xml refers to different site - spam spam spam
+ echo "<div class=\"errors\">The submitted URL does not ";
+ echo "appear to point to a valid channel site. You will ";
+ echo "have to make sure that <tt>/channel.xml</tt> at least ";
+ echo "exists and is valid. In addition, it must refer to ";
+ echo "your channel. If you think that this mechanism does not work ";
+ echo "properly, please drop a mail to the ";
+ echo '<a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">webmasters</a>.';
+ echo "</div>";
- $form->display();
- break;
- }
- $text = sprintf("[Channels] Please add %s (%s) to the channel index.",
- $form->exportValue("project[name]"),
- $form->exportValue("project[link]"));
- $from = sprintf('"%s" <%s>',
- $form->exportValue("name"),
- $form->exportValue("email"));
+ echo $form;
+ break;
+ }
+ $text = sprintf("[Channels] Please add %s (%s) to the channel index.",
+ $project_name->getValue(),
+ $link->getValue());
+ $from = sprintf('"%s" <%s>',
+ $name->getValue(),
+ $email->getValue());
- $logger = new Damblan_Log;
+ $logger = new Damblan_Log;
- $observer = new Damblan_Log_Mail;
- $observer->setRecipients(PEAR_WEBMASTER_EMAIL);
- $observer->setHeader("From", $from);
- $observer->setHeader("Subject", "Channel link submission");
- $logger->attach($observer);
+ $observer = new Damblan_Log_Mail;
+ $observer->setRecipients(PEAR_WEBMASTER_EMAIL);
+ $observer->setHeader("From", $from);
+ $observer->setHeader("Subject", "Channel link submission");
+ $logger->attach($observer);
- $logger->log($text);
+ $logger->log($text);
- echo "<div class=\"success\">Thanks for your submission. It will ";
- echo "be reviewed as soon as possible.</div>\n";
- } while (false);
+ echo "<div class=\"success\">Thanks for your submission. It will ";
+ echo "be reviewed as soon as possible.</div>\n";
+ } while (false);
+ }
+ } catch (HTTP_Request2_Exception $exception) {
+ echo '<div class="errors">';
+ echo $exception->getMessage();
+ echo "</div>";
+
+ echo $form;
}
} else {
- $form->display();
+ echo $form;
echo "<p>The "Project Link" should not point to the main ";
echo "homepage of the project, but rather to a page with installation ";