svn: /pear/pearweb/trunk/ include/HTML/QuickForm2/Renderer/PEAR.php package.xml public_html/account-request-newpackage.php public_html/css/style.css

[email protected] ("Daniel O'Connor") Wed, 13 Apr 2011 02:21:00 +0000
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
clockwerx                                Wed, 13 Apr 2011 02:21:00 +0000

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

Log:
Upgrade to QF2

Changed paths:
    A   pear/pearweb/trunk/include/HTML/QuickForm2/Renderer/
    A   pear/pearweb/trunk/include/HTML/QuickForm2/Renderer/PEAR.php
    U   pear/pearweb/trunk/package.xml
    U   pear/pearweb/trunk/public_html/account-request-newpackage.php
    U   pear/pearweb/trunk/public_html/css/style.css
svn-diffs-310178.txt (text/x-diff, 12.8 KB)
Added: pear/pearweb/trunk/include/HTML/QuickForm2/Renderer/PEAR.php
===================================================================
--- pear/pearweb/trunk/include/HTML/QuickForm2/Renderer/PEAR.php	                        (rev 0)
+++ pear/pearweb/trunk/include/HTML/QuickForm2/Renderer/PEAR.php	2011-04-13 02:21:00 UTC (rev 310178)
@@ -0,0 +1,18 @@
+<?php
+require_once 'HTML/QuickForm2/Renderer/Default.php';
+
+/**
+ * A custom Quickform2 renderer, which skips the factory/proxy behaviour.
+ *
+ * Additionally, it has a different template for grouped form controls (typically checkboxes)
+ *
+ * @bug http://pear.php.net/bugs/bug.php?id=18435&thanks=4
+ */
+class HTML_QuickForm2_Renderer_PEAR extends HTML_QuickForm2_Renderer_Default {
+    public function __construct() {
+        $checkbox_template = '<label for="{id}" class="element <qf:error> error</qf:error>"><qf:required><span class="required">* </span></qf:required>{element} {label}</label><br />
+<qf:error><span class="error">{error}</span></qf:error>';
+
+        $this->setElementTemplateForGroupClass('html_quickform2_container', 'html_quickform2_element_inputcheckable', $checkbox_template);
+    }
+}

Modified: pear/pearweb/trunk/package.xml
===================================================================
--- pear/pearweb/trunk/package.xml	2011-04-13 00:32:55 UTC (rev 310177)
+++ pear/pearweb/trunk/package.xml	2011-04-13 02:21:00 UTC (rev 310178)
@@ -90,7 +90,7 @@
   <active>yes</active>
  </developer>
  <date>2011-04-13</date>
- <time>09:29:56</time>
+ <time>11:14:26</time>
  <version>
   <release>1.24.3</release>
   <api>0.1.1</api>
@@ -188,6 +188,9 @@
        <file name="InputNumber.php" role="www" />
        <file name="InputUrl.php" role="www" />
       </dir> <!-- /include/HTML/QuickForm2/Element -->
+      <dir name="Renderer">
+       <file name="PEAR.php" role="www" />
+      </dir> <!-- /include/HTML/QuickForm2/Renderer -->
      </dir> <!-- /include/HTML/QuickForm2 -->
     </dir> <!-- /include/HTML -->
     <dir name="package">

Modified: pear/pearweb/trunk/public_html/account-request-newpackage.php
===================================================================
--- pear/pearweb/trunk/public_html/account-request-newpackage.php	2011-04-13 00:32:55 UTC (rev 310177)
+++ pear/pearweb/trunk/public_html/account-request-newpackage.php	2011-04-13 02:21:00 UTC (rev 310178)
@@ -18,10 +18,19 @@
    $Id$
 */

-require_once 'HTML/QuickForm.php';
+require_once 'HTML/QuickForm2.php';
+require_once 'HTML/QuickForm2/Renderer/PEAR.php';
+/** @todo Remove once these are in QF2 */
+
+
+require_once 'HTML/QuickForm2/Element/InputNumber.php';
+require_once 'HTML/QuickForm2/Element/InputEmail.php';
+require_once 'HTML/QuickForm2/Element/InputUrl.php';
+
 require_once 'Damblan/Mailer.php';
 require_once 'Text/CAPTCHA/Numeral.php';
 require_once 'Services/ProjectHoneyPot.php';
+require_once 'pear-database-user.php';

 $numeralCaptcha = new Text_CAPTCHA_Numeral();
 session_start();
@@ -29,8 +38,8 @@
 $display_form = true;
 $width        = 60;
 $errors       = array();
-$jumpto       = 'handle';

+
 $stripped = @array_map('strip_tags', $_POST);
 response_header('Request Account');

@@ -79,7 +88,7 @@
         }

         //  The add method performs further validation then creates the account
-        include_once 'pear-database-user.php';
+
         $ok = user::add($stripped);
         if (PEAR::isError($ok)) {
             $errors[] = 'This email address has already been registered by another user';
@@ -88,10 +97,6 @@
         }


-        if (!empty($stripped['jumpto'])) {
-            $jumpto = $stripped['jumpto'];
-        }
-
         if (isset($stripped['display_form'])) {
             $display_form = $stripped['display_form'];
         }
@@ -132,26 +137,40 @@
     //$resolver = new Net_DNS_Resolver;
     //$resolver->nameservers = array('66.114.197.251');

-    $sphp = Services_ProjectHoneyPot::factory(HONEYPOT_API_KEY, $resolver);
+    $sphp = new Services_ProjectHoneyPot(HONEYPOT_API_KEY, $resolver);
     $sphp->setResponseFormat('object');
     $ip = $_SERVER['REMOTE_ADDR'];
     // Uncomment for testing or get one from http://www.projecthoneypot.org/top_harvesters.php
     // $ip = '209.85.138.136';
-    $status = $sphp->query($ip);
+    $results = $sphp->query($ip);
 } catch (Services_ProjectHoneyPot_Exception $e) {
    report_error($e);
    $display_form = false;
 }

-// Check about the last 30 days
-if ($status && $status->getLastActivity() < 30
-    && ($status->suspicious || $status->isCommentSpammer() || $status->isHarvester() || $status->isSearchEngine())
-) {
-    $errors = 'We can not allow you to continue since your IP has been marked suspicious within the past 30 days
-            by the http://projecthoneypot.org/, if that was done in error then please contact ' .
-               PEAR_DEV_EMAIL . ' as well as the projecthoneypot people to resolve the issue.';
-    report_error($errors);
-    $display_form = false;
+foreach ($results as $status) {
+    foreach ($status as $ip => $item) {
+        if (empty($item)) {
+           continue;
+        }
+
+        foreach ($status as $ip => $item) {
+            if (empty($item)) {
+               continue;
+            }
+
+            if ($status->getLastActivity() < 30 && ($status->isCommentSpammer()
+                                                     || $status->isHarvester()
+                                                     || $status->isSearchEngine())) {
+                // Check about the last 30 days
+                $errors = 'We can not allow you to continue since your IP has been marked suspicious within the past 30 days
+                        by the http://projecthoneypot.org/, if that was done in error then please contact ' .
+                           PEAR_DEV_EMAIL . ' as well as the projecthoneypot people to resolve the issue.';
+                report_error($errors);
+                $display_form = false;
+            }
+        }
+    }
 }

 if ($display_form) {
@@ -179,36 +198,15 @@

     report_error($errors);

-    $form = new HTML_QuickForm('account-request-newpackage', 'post', 'account-request-newpackage.php#requestform');
+    $form = new HTML_QuickForm2('account-request-newpackage', 'post', array('action' => 'account-request-newpackage.php#requestform'));
     $form->removeAttribute('name');

-    $renderer =& $form->defaultRenderer();
-    $renderer->setElementTemplate('
- <tr>
-  <th class="form-label_left">
-   <!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required -->
-   {label}
-  </th>
-  <td class="form-input">
-   <!-- BEGIN error --><span style="color: #ff0000">{error}</span><br /><!-- END error -->
-   {element}
-  </td>
- </tr>
-');
+    $renderer = new HTML_QuickForm2_Renderer_PEAR();

-    $renderer->setFormTemplate('
-<form{attributes}>
- <div>
-  {hidden}
-  <table border="0" class="form-holder" cellspacing="1">
-   {content}
-  </table>
- </div>
-</form>');

     $hsc = array_map('htmlspecialchars', $stripped);
     // Set defaults for the form elements
-    $form->setDefaults(array(
+    $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array(
         'handle'        => @$hsc['handle'],
         'firstname'     => @$hsc['firstname'],
         'lastname'      => @$hsc['lastname'],
@@ -220,55 +218,54 @@
         'homepage'      => @$hsc['homepage'],
         'moreinfo'      => @$hsc['moreinfo'],
         'comments_read' => @$hsc['comments_read'],
-    ));
+    )));

-    $form->addElement('html', '<caption class="form-caption">Request Account</caption>');
-    $form->addElement('text', 'handle', 'Use<span class="accesskey">r</span>name:',
-            'size="12" maxlength="20" accesskey="r"');
-    $form->addElement('text', 'firstname', 'First Name:', array('size' => 30));
-    $form->addElement('text', 'lastname', 'Last Name:', array('size' => 30));
-    $form->addElement('password', 'password', 'Password:', array('size' => 10));
-    $form->addElement('password', 'password2', 'Repeat Password:', array('size' => 10));
-    $text  = $numeralCaptcha->getOperation() . ' = <input type="text" size="4" maxlength="4" name="captcha" />';
-    $form->addElement('static', null, 'Solve the problem:', $text);
+    $form->addElement('text', 'handle', array('placeholder' => 'psmith', 'maxlength' => "20", 'accesskey' => "r", 'required' => 'required'))->setLabel('Use<span class="accesskey">r</span>name:');
+
+    $form->addElement('text', 'firstname', array('placeholder' => 'Peter', 'required' => 'required'))->setLabel('First Name:');
+    $form->addElement('text', 'lastname', array('placeholder' => 'Smith', 'required' => 'required'))->setLabel('Last Name:');
+    $form->addElement('password', 'password', array('size' => 10, 'required' => 'required'))->setLabel('Password:');
+    $form->addElement('password', 'password2', array('size' => 10, 'required' => 'required'))->setLabel('Repeat Password:');
+    $form->addElement('number', 'captcha', array('maxlength' => 4, 'required' => 'required'))->setLabel("What is " . $numeralCaptcha->getOperation() . '?');
     $_SESSION['answer'] = $numeralCaptcha->getAnswer();
-    $form->addElement('text', 'email', 'Email Address:', array('size' => 20));
-    $form->addElement('checkbox', 'showemail', 'Show email address?');
-    $form->addElement('text', 'newpackage', 'Proposed Package Name:', array('size' => 20));

+
+    $form->addElement('email', 'email', array('placeholder' => '[email protected]', 'required' => 'required'))->setLabel('Email Address:');
+    $form->addElement('checkbox', 'showemail')->setLabel( 'Show email address?');
+    $form->addElement('text', 'newpackage', array('placeholder' => 'Category_PackageName', 'required' => 'required'))->setLabel('Proposed Package Name:');
+
     $invalid_purposes = array(
         'Propose a new, incomplete package, or an incomplete idea for a package',
         'Browse ' . PEAR_CHANNELNAME . '.'
     );

+    $purpose = $form->addGroup('purpose')->setLabel('Purpose of your PEAR account:');
+
     $checkbox = array();
     foreach ($invalid_purposes as $i => $purposeKey) {
-        $el = &HTML_QuickForm::createElement('checkbox', $i, null, ' ' . $purposeKey);
-        $el->setValue(@$_POST['purposecheck'][$i]);
-        $checkbox[] = $el;
+        $purpose->addElement('checkbox', 'purposecheck[' . $i . ']')
+                ->setLabel($purposeKey)
+                ->setValue(@$_POST['purposecheck'][$i]);
     }
-    $form->addGroup($checkbox, 'purposecheck', 'Purpose of your PEAR account:'
-            . '<p class="cell_note">(Check all that apply)</p>', '<br />');

     $form->addElement('textarea', 'purpose',
-            'Short summary of package that you have finished and are ready to propose:',
-            array('cols' => 40, 'rows' => 5));
-    $form->addElement('text', 'sourcecode', 'Link to browseable online source code:', array('size' => 40));
-    $form->addElement('text', 'homepage', 'Homepage:'
-            . '<p class="cell_note">(optional)</p>', array('size' => 40));
+            array('cols' => 40, 'rows' => 5, 'required' => 'required'))
+         ->setLabel('Short summary of package that you have finished and are ready to propose:');
+
+    $form->addElement('url', 'sourcecode', array('placeholder' => 'http://example.com/svn/', 'required' => 'required'))
+         ->setLabel('Link to browseable online source code:');
+
+    $form->addElement('url', 'homepage', array('placeholder' => 'http://example.com'))->setLabel('Homepage:'
+            . '<p class="cell_note">(optional)</p>');
     $form->addElement('textarea', 'moreinfo',
-            'More relevant information about you:'
-            . '<p class="cell_note">(optional)</p>',
-            array('cols' => 40, 'rows' => 5));
-    $form->addElement('checkbox', 'comments_read', 'I have read EVERYTHING on this page:');
-    $form->addElement('submit', 'submit', 'Submit Request');
-    $form->display();
+            array('cols' => 40, 'rows' => 5, 'placeholder' => "I am a developer who has ..."))->setLabel('More relevant information about you:'
+            . '<p class="cell_note">(optional)</p>');
+    $form->addElement('checkbox', 'comments_read', array('required' => 'required'))->setLabel('I have read EVERYTHING on this page:');
+    $form->addElement('submit', 'submit')->setLabel('Submit Request');

-    if ($jumpto) {
-        print "<script type=\"text/javascript\">\n<!--\n";
-        print "if (!document.forms[1].$jumpto.disabled) document.forms[1].$jumpto.focus();\n";
-        print "\n// -->\n</script>\n";
-    }
+    print $form->render($renderer);
+
+
 }

 response_footer();

Modified: pear/pearweb/trunk/public_html/css/style.css
===================================================================
--- pear/pearweb/trunk/public_html/css/style.css	2011-04-13 00:32:55 UTC (rev 310177)
+++ pear/pearweb/trunk/public_html/css/style.css	2011-04-13 02:21:00 UTC (rev 310178)
@@ -382,6 +382,9 @@
     vertical-align: top;
     background-color: #e8e8e8;
 }
+div.element.group {
+    background-color: inherit;
+}

 td.form-input_center {
     padding: 3px;