Переглянути джерело

Add password option widget

pdontthink 16 роки тому
батько
коміт
6de4d8ae69
4 змінених файлів з 26 додано та 6 видалено
  1. 1 0
      ChangeLog
  2. 9 4
      functions/forms.php
  3. 15 2
      functions/options.php
  4. 1 0
      include/constants.php

+ 1 - 0
ChangeLog

@@ -266,6 +266,7 @@ Version 1.5.2 - SVN
   - Allow control over white space wrapping of auto-generated SquirrelMail
     option widgets.
   - Add informational type option widget
+  - Add password type option widget
 
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------

+ 9 - 4
functions/forms.php

@@ -76,12 +76,17 @@ function addInputField($sType, $aAttribs=array()) {
  * Password input field
  * @param string $sName field name
  * @param string $sValue initial password value
- * @param array $aAttribs (since 1.5.1) extra attributes
- * @return string html formated password field
+ * @param integer $iSize field size (number of characters)
+ * @param integer $iMaxlength maximum number of characters the user may enter
+ * @param array $aAttribs (since 1.5.1) extra attributes - should be given
+ *                        in the form array('attribute_name' => 'attribute_value', ...)
+ * @return string html formated password field 
  */
-function addPwField($sName, $sValue = null, $aAttribs=array()) {
+function addPwField($sName, $sValue = '', $iSize = 0, $iMaxlength = 0, $aAttribs=array()) {
     $aAttribs['name']  = $sName;
-    $aAttribs['value'] = (! is_null($sValue) ? $sValue : '');
+    $aAttribs['value'] = $sValue;
+    if ($iSize) $aAttribs['size'] = (int)$iSize;
+    if ($iMaxlength) $aAttribs['maxlength'] = (int)$iMaxlength;
     // add default css
     if (! isset($aAttribs['class'])) $aAttribs['class'] = 'sqmpwfield';
     return addInputField('password',$aAttribs);

+ 15 - 2
functions/options.php

@@ -364,6 +364,9 @@ class SquirrelOption {
 
         /* Get the widget for this option type. */
         switch ($this->type) {
+            case SMOPT_TYPE_PASSWORD:
+                $result = $this->createWidget_String(TRUE);
+                break;
             case SMOPT_TYPE_STRING:
                 $result = $this->createWidget_String();
                 break;
@@ -443,9 +446,15 @@ class SquirrelOption {
 
     /**
      * Create string field
+     *
+     * @param boolean $password When TRUE, the text in the input
+     *                          widget will be obscured (OPTIONAL;
+     *                          default = FALSE).
+     *
      * @return string html formated option field
+     *
      */
-    function createWidget_String() {
+    function createWidget_String($password=FALSE) {
         switch ($this->size) {
             case SMOPT_SIZE_TINY:
                 $width = 5;
@@ -465,7 +474,11 @@ class SquirrelOption {
         }
 
 //TODO: might be better to have a separate template file for all widgets, because then the layout of the widget and the "trailing text" can be customized - they are still hard coded here
-        return addInput('new_' . $this->name, $this->value, $width, 0, $this->aExtraAttribs) . ' ' . htmlspecialchars($this->trailing_text);
+        if ($password)
+addPwField($sName, $sValue = null, $aAttribs=array()) {
+            return addPwField('new_' . $this->name, $this->value, $width, 0, $this->aExtraAttribs) . ' ' . htmlspecialchars($this->trailing_text);
+        else
+            return addInput('new_' . $this->name, $this->value, $width, 0, $this->aExtraAttribs) . ' ' . htmlspecialchars($this->trailing_text);
     }
 
     /**

+ 1 - 0
include/constants.php

@@ -236,6 +236,7 @@ define('SMOPT_TYPE_BOOLEAN_RADIO', 13);
 define('SMOPT_TYPE_STRLIST_RADIO', 14);
 define('SMOPT_TYPE_SUBMIT', 15);
 define('SMOPT_TYPE_INFO', 16);
+define('SMOPT_TYPE_PASSWORD', 17);
 
 // Define constants for the layout scheme for edit lists
 define('SMOPT_EDIT_LIST_LAYOUT_LIST', 0);