コード例 #1
0
/** construct a listbox
 *
 * this constructs a listbox
 *
 * The number of lines in the result depends on the number of items in the
 * options array in $item. The result always starts with a SELECT opening tag,
 * followed by N OPTION tags and finally a SELECT closing tag.
 *
 * There are two different ways to specify the options. The simple way is to
 * have a single options array with 'value' => 'option text' pairs. In this case
 * the available properties such as title, class and viewonly are copied from
 * the corresonding generic properties in the $item array,
 *
 * The other way is to have an array of arrays like this:
 * <code>
 * $item['options'] = array('1'=>array('title'=>'...','option'=>'...'),2 => array(...));
 * </code>
 *
 * This allows for setting properties of individual options, e.g. one of the
 * options could be made viewonly while the others are still selectable.
 *
 * The properties recognised translate to the following HTML-code/attributes
 * <pre>
 * name      : name
 * value     : value AND perhaps 'selected' if value matches option value
 * accesskey : accesskey
 * alt       : alt
 * class     : class (also depends on viewonly and errors)
 * tabindex  : tabindex
 * id        : id
 * title     : title
 * viewonly  : disabled AND addition of ATTR_CLASS_ERROR to class list (if viewonly == TRUE)
 * errors    : addition of ATTR_CLASS_ERROR to class list (if errors > 0)
 * label     : tilde+letter may change the accesskey
 * </pre>
 *
 * Note that the options within the SELECT tag are indented 2 spaces for readability.
 *
 * @param array &$item the parameters that describe the dialog input element
 * @param string $name the name of the input element ('fieldname')
 * @param mixed $value the (current) value of the input element to show ('field value')
 * @param string $f_type the type of the field (eg text, number, date, time, ...)
 * @return array 2 or more lines of ready-to-use HTML
 */
function dialog_get_widget_listbox(&$item, $name, $value)
{
    // some browsers insist on a tight link between label and select
    if ($item['type'] == F_LISTBOX && !isset($item['id'])) {
        $item['id'] = 'id' . strval(get_unique_number());
        // assign a unique id for every item
    }
    $attributes = array('name' => $name);
    if (isset($item['rows']) && $item['rows'] > 1) {
        $attributes['size'] = $item['rows'];
    }
    $options_attributes = array();
    $class = dialog_get_class($item);
    if (!empty($class)) {
        $attributes['class'] = $class;
        $options_attributes['class'] = $class;
    }
    $hotkey = isset($item['label']) ? accesskey_from_string($item['label']) : '';
    if (!empty($hotkey)) {
        $attributes['accesskey'] = $hotkey;
    } elseif (isset($option['accesskey'])) {
        $attributes['accesskey'] = $option['accesskey'];
    }
    if (isset($item['tabindex'])) {
        $attributes['tabindex'] = $item['tabindex'];
    }
    if (isset($item['title'])) {
        $attributes['title'] = $item['title'];
        $options_attributes['title'] = $item['title'];
    }
    if (isset($item['id'])) {
        $attributes['id'] = $item['id'];
    }
    if (isset($item['viewonly']) && $item['viewonly']) {
        $attributes['disabled'] = NULL;
    }
    $a = array(html_tag('select', $attributes));
    if (isset($item['options']) && is_array($item['options']) && !empty($item['options'])) {
        foreach ($item['options'] as $option_value => $option) {
            $attributes = $options_attributes;
            // freshly inherited from select tag
            $attributes['value'] = $option_value;
            if ($value == $option_value) {
                $attributes['selected'] = NULL;
            }
            if (is_array($option)) {
                if (isset($option['class'])) {
                    $attributes['class'] = dialog_get_class($item, $option['class']);
                }
                if (isset($option['title'])) {
                    $attributes['title'] = $option['title'];
                }
                if (isset($option['id'])) {
                    $attributes['id'] = $option['id'];
                }
                if (isset($option['viewonly']) && $option['viewonly']) {
                    $attributes['disabled'] = NULL;
                }
                $label = isset($option['option']) ? $option['option'] : $option_value;
            } else {
                $label = !empty($option) ? $option : $option_value;
            }
            $a[] = '  ' . html_tag('option', $attributes, htmlspecialchars($label));
        }
    }
    $a[] = '</select>';
    return $a;
}
コード例 #2
0
 /** construct a message-id conforming to RFC5322 (RFC2822, RFC822)
  *
  * This constructs a message id according to specifications in section
  * 3.6.4 in RFC5322 Internet Message Format (October 2008),
  * see {@link http://www.ietf.org/rfc/rfc5322.txt}.
  *
  * Note that the 'id-left' in the 'msg-id' also contains the remote
  * IP-address. This could be an IPv4 address in the usual dotted-decimal
  * form but it could also be an IPv6 address like '::1' (3 characters) or
  * '[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]' (41 characters).
  * The total maximum-length of 'id-left' may add up to
  * 11 (32-bit signed pid) + 1 (dot) + 41 (full IPv6 w/ brackets) + 1 (hash) +
  * 11 (32-bit signed remote port) + 1 (dot) + 14 (date/time) + 11 (signed
  * unique number) = 91 characters. This is longer than the recommended
  * linelength of 78 characters, but the absolute maximum of 998 characters
  * will probably NOT be reached. OTOH: we do not actually check for
  * huge domain names and/or server names. Oh well.
  *
  * Note that we massage the IPv6 address by replacing any ':', '[' and ']'
  * with '!', '{' and '}' respectively because the former are not allowed in
  * a dot-atom-text. As a matter of fact we translate most 'specials' to
  * 'atext' (RFC5322 3.2.3). Notable exception: the dot stays.
  *
  * @return string message-id according to RFC5322 section 3.6.4
  * @todo how about UTF-8 hostnames? Mmmm...
  */
 function rfc5322_message_id()
 {
     global $CFG;
     // 1 -- construct id-right according to RFC5322
     $id_right = '';
     // 1A -- try bare host/domain name from this site's URL
     if (($url = parse_url($CFG->www)) !== FALSE) {
         // labels [RFC1035] are dot-atom-text [RFC5322] hence the ereg_replace()
         $id_right = isset($url['host']) ? trim(ereg_replace('[^a-zA-Z0-9.-]', '', $url['host']), '.') : '';
     }
     // 1B -- if no joy, try the server name
     if (empty($id_right) && isset($_SERVER['SERVER_NAME'])) {
         $id_right = trim(ereg_replace('[^a-zA-Z0-9.-]', '', $_SERVER['SERVER_NAME']), '.');
     }
     // 1C -- last resort: localhost
     if (empty($id_right)) {
         $id_right = 'localhost.localdomain';
         // last resort
     }
     // 2 -- construct msg-id with a hopefully unique id-left
     $msg_id = sprintf('<%d.%s#%d.%s.%d@%s>', intval(getmypid()), isset($_SERVER['REMOTE_ADDR']) ? strtr($_SERVER['REMOTE_ADDR'], ':[]()<>;@,\\', '!{}{}{}!*-/') : '127.0.0.1', isset($_SERVER['REMOTE_PORT']) ? intval($_SERVER['REMOTE_PORT']) : 42, strftime('%Y%m%d%H%M%S'), get_unique_number(), $id_right);
     return $msg_id;
 }