当前位置: 首页>>代码示例>>PHP>>正文


PHP Pieform::hsc方法代码示例

本文整理汇总了PHP中Pieform::hsc方法的典型用法代码示例。如果您正苦于以下问题:PHP Pieform::hsc方法的具体用法?PHP Pieform::hsc怎么用?PHP Pieform::hsc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pieform的用法示例。


在下文中一共展示了Pieform::hsc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: pieform_element_expiry

/**
 * Provides a duration chooser, with a text box for a number and a
 * select box to choose the units, in days, weeks, months, years, or 'no end date'.
 *
 * @param Pieform $form    The form to render the element for
 * @param array   $element The element to render
 * @return string          The HTML for the element
 */
function pieform_element_expiry(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    $result = '';
    $name = Pieform::hsc($element['name']);
    if (!isset($element['defaultvalue'])) {
        $element['defaultvalue'] = null;
    }
    $global = $form->get_property('method') == 'get' ? $_GET : $_POST;
    // Get the value of the element for rendering.
    if (isset($element['value'])) {
        $seconds = $element['value'];
        $values = pieform_element_expiry_get_expiry_from_seconds($element['value']);
    } else {
        if ($form->is_submitted() && isset($global[$element['name']]) && isset($global[$element['name'] . '_units'])) {
            $values = array('number' => $global[$element['name']], 'units' => $global[$element['name'] . '_units']);
            $seconds = $values['number'] * pieform_element_expiry_seconds_in($values['units']);
        } else {
            if (isset($element['defaultvalue'])) {
                $seconds = $element['defaultvalue'];
                $values = pieform_element_expiry_get_expiry_from_seconds($seconds);
            } else {
                $values = array('number' => '', 'units' => 'noenddate');
                $seconds = null;
            }
        }
    }
    // @todo probably create with an actual input element, as tabindex doesn't work here for one thing
    // Same with the select. And do the events using mochikit signal instead of dom events
    $numberinput = '<input';
    $numberinput .= $values['units'] == 'noenddate' && empty($element['rules']['required']) ? ' disabled="disabled"' : '';
    $numberinput .= ' type="text" size="4" name="' . $name . '"';
    $numberinput .= ' id="' . $formname . '_' . $name . '" value="' . Pieform::hsc($values['number']) . '" tabindex="' . Pieform::hsc($element['tabindex']) . '"';
    $numberinput .= (isset($element['error']) ? ' class="error"' : '') . ">\n";
    $uselect = '<select onchange="' . $name . '_change()" ';
    $uselect .= 'name="' . $name . '_units" id="' . $formname . '_' . $name . '_units"' . ' tabindex="' . Pieform::hsc($element['tabindex']) . "\">\n";
    foreach (pieform_element_expire_get_expiry_units() as $u) {
        // Don't allow 'no end date' if the element is required
        if ($u == 'noenddate' && !empty($element['rules']['required'])) {
            continue;
        }
        $uselect .= "\t<option value=\"{$u}\"" . ($values['units'] == $u ? ' selected="selected"' : '') . '>' . $form->i18n('element', 'expiry', $u, $element) . "</option>\n";
    }
    $uselect .= "</select>\n";
    // Make sure the input is disabled if "no end date" is selected
    $script = <<<EOJS
<script type="text/javascript" language="javascript">
function {$name}_change() {
    if (\$('{$formname}_{$name}_units').value == 'noenddate') {
        \$('{$formname}_{$name}').disabled = true;
    }
    else {
        \$('{$formname}_{$name}').disabled = false;
    }
}
</script>
EOJS;
    return $numberinput . $uselect . $script;
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:68,代码来源:expiry.php

示例2: pieform_element_checkbox

/**
 * Provides a basic checkbox input.
 *
 * @param Pieform  $form    The form to render the element for
 * @param array    $element The element to render
 * @return string           The HTML for the element
 */
function pieform_element_checkbox(Pieform $form, $element)
{
    /*{{{*/
    $checked = false;
    if (isset($element['rules']['required'])) {
        throw new PieformException("For pieform_element_checkbox, 'required' is not allowed as a rule. Radio should be used instead.");
    }
    if (!empty($element['value'])) {
        $checked = true;
    }
    $global = $form->get_property('method') == 'get' ? $_GET : $_POST;
    if ($form->is_submitted() && isset($global[$element['name']])) {
        $checked = true;
    } else {
        if (!$form->is_submitted() && !empty($element['defaultvalue'])) {
            $checked = true;
        } else {
            if (!empty($element['readonly']) && !empty($element['defaultvalue'])) {
                $checked = true;
            }
        }
    }
    $arialabel = '';
    if (!empty($element['arialabel'])) {
        $arialabel = ' aria-label="' . Pieform::hsc($element['title']) . '"';
    }
    return '<input type="checkbox"' . $form->element_attributes($element) . $arialabel . ($checked ? ' checked="checked"' : '') . '>';
}
开发者ID:rboyatt,项目名称:mahara,代码行数:35,代码来源:checkbox.php

示例3: pieform_element_textarea

/**
 * Renders a basic HTML <textarea> element.
 *
 * @param array    $element The element to render
 * @param Pieform  $form    The form to render the element for
 * @return string           The HTML for the element
 */
function pieform_element_textarea(Pieform $form, $element)
{
    /*{{{*/
    global $_PIEFORM_TEXTAREAS;
    $rows = $cols = $style = '';
    if (isset($element['height'])) {
        $style .= 'height:' . $element['height'] . ';';
        $rows = intval($element['height'] > 0) ? ceil(intval($element['height']) / 10) : 1;
    } elseif (isset($element['rows'])) {
        $rows = $element['rows'];
    } else {
        Pieform::info('No value for rows or height specified for textarea "' . $element['name'] . '"');
    }
    if (isset($element['width'])) {
        $style .= 'width:' . $element['width'] . ';';
        $cols = intval($element['width'] > 0) ? ceil(intval($element['width']) / 10) : 1;
    } elseif (isset($element['cols'])) {
        $cols = $element['cols'];
    } else {
        Pieform::info('No value for cols or width specified for textarea "' . $element['name'] . '"');
    }
    $element['style'] = isset($element['style']) ? $style . $element['style'] : $style;
    $fullwidth = !empty($element['fullwidth']) ? 'true' : 'false';
    if (!empty($element['resizable'])) {
        $element['class'] = isset($element['class']) && $element['class'] ? $element['class'] . ' resizable' : 'resizable';
        $_PIEFORM_TEXTAREAS[] = array('formname' => $form->get_name(), 'elementname' => $form->get_name() . '_' . $element['id'], 'fullwidth' => $fullwidth);
    }
    return '<textarea' . ($rows ? ' rows="' . $rows . '"' : '') . ($cols ? ' cols="' . $cols . '"' : '') . $form->element_attributes($element, array('maxlength', 'size')) . '>' . Pieform::hsc($form->get_value($element)) . '</textarea>';
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:36,代码来源:textarea.php

示例4: pieform_renderer_oneline

/**
 * Renders form elements all on one line.
 *
 * @param Pieform $form    The form the element is being rendered for
 * @param array   $element The element that is being rendered
 * @return string          The element rendered inside an appropriate container
 */
function pieform_renderer_oneline(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    // Set the class of the enclosing <div> to match that of the element
    $result = '<span';
    if (isset($element['name'])) {
        $result .= ' id="' . $formname . '_' . Pieform::hsc($element['name']) . '_container"';
    }
    if (!empty($element['class'])) {
        // add form-group classes to all real form fields
        if (strpos($element['class'], 'html') === false) {
            // $element['class'] = $element['class'] . ' form-group-inline';
            $element['class'] = 'form-group-inline';
        }
        // add bootstrap has-error class to any error fields
        if (strpos($element['class'], 'error') !== false) {
            $element['class'] = $element['class'] . ' has-error';
        }
        $result .= ' class="' . Pieform::hsc($element['class']) . '"';
    }
    $result .= '>';
    if (isset($element['labelhtml'])) {
        $result .= $element['labelhtml'];
    }
    if (isset($element['prehtml'])) {
        $result .= '<span class="prehtml">' . $element['prehtml'] . '</span>';
    }
    $result .= $element['html'];
    if (isset($element['posthtml'])) {
        $result .= '<span class="posthtml">' . $element['posthtml'] . '</span>';
    }
    $result .= "</span>";
    return $result;
}
开发者ID:rboyatt,项目名称:mahara,代码行数:42,代码来源:oneline.php

示例5: pieform_element_hidden

/**
 * Renders a hidden element.
 *
 * @param Pieform $form  The form to render the element for
 * @param array $element The element to render
 * @return string        The HTML for the element
 */
function pieform_element_hidden(Pieform $form, $element)
{
    /*{{{*/
    if (!array_key_exists('value', $element)) {
        throw new PieformException('The hidden element "' . $element['name'] . '" must have a value set');
    }
    if (!empty($element['sesskey']) && $form->get_property('method') != 'post') {
        throw new PieformException('Sesskey values should be POSTed');
    }
    $value = $form->get_value($element);
    if (is_array($value)) {
        $result = '';
        foreach ($value as $k => $v) {
            if (is_array($v)) {
                foreach ($v as $subk => $subv) {
                    $result .= '<input type="hidden" name="' . Pieform::hsc($element['name']) . '[' . Pieform::hsc($k) . '][' . Pieform::hsc($subk) . ']" value="' . Pieform::hsc($subv) . "\">\n";
                }
            } else {
                $result .= '<input type="hidden" name="' . Pieform::hsc($element['name']) . '[' . Pieform::hsc($k) . ']" value="' . Pieform::hsc($v) . "\">\n";
            }
        }
        return $result;
    }
    return '<input type="hidden"' . $form->element_attributes($element, array('accesskey', 'onclick', 'size', 'style', 'tabindex')) . ' value="' . Pieform::hsc($form->get_value($element)) . "\">\n";
}
开发者ID:rboyatt,项目名称:mahara,代码行数:32,代码来源:hidden.php

示例6: pieform_element_button

/**
 * Renders an <input type="button"> element.
 *
 * The element must have the 'value' field set.
 *
 * @param Pieform $form    The form to render the element for
 * @param array   $element The element to render
 * @return string          The HTML for the element
 * @todo rename to inputbutton
 */
function pieform_element_button(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['value'])) {
        throw new PieformException('Button elements must have a value');
    }
    if (isset($element['confirm'])) {
        $element['data-confirm'] = Pieform::hsc($element['confirm']);
    }
    $element['class'] .= ' btn';
    if (isset($element['usebuttontag']) && $element['usebuttontag'] === true) {
        $value = '';
        $action = '';
        $type = 'type="submit" ';
        if (isset($element['content'])) {
            $content = $element['content'];
            $value = 'value="' . Pieform::hsc($element['value']) . '" ';
        } else {
            $content = $element['value'];
        }
        if (isset($element['action'])) {
            $action = 'formaction="' . Pieform::hsc($element['action']) . '" ';
        }
        $button = '<button ' . $value . $action . $type . $form->element_attributes($element) . '>' . $content . '</button>';
    } else {
        $button = '<input type="button"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($element['value']) . '">';
    }
    return $button;
}
开发者ID:rboyatt,项目名称:mahara,代码行数:39,代码来源:button.php

示例7: pieform_renderer_div

/**
 * Renders form elements inside <div>s.
 *
 * @param Pieform $form    The form the element is being rendered for
 * @param array   $element The element to be rendered
 * @return string          The element rendered inside an appropriate container
 */
function pieform_renderer_div(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    // Set the class of the enclosing <div> to match that of the element
    $result = '<div';
    if (isset($element['name'])) {
        $result .= ' id="' . $formname . '_' . $element['name'] . '_container"';
    }
    if (!empty($element['class'])) {
        $result .= ' class="' . $element['class'] . '"';
    }
    $result .= '>';
    if (isset($element['labelhtml'])) {
        $result .= $element['labelhtml'];
    }
    //$result .= $builtelement;
    $result .= $element['html'];
    if (isset($element['helphtml'])) {
        $result .= ' ' . $element['helphtml'];
    }
    // Description - optional description of the element, or other note that should be visible
    // on the form itself (without the user having to hover over contextual help
    if ((!$form->has_errors() || $form->get_property('showdescriptiononerror')) && !empty($element['description'])) {
        $result .= '<div class="description"> ' . Pieform::hsc($element['description']) . "</div>";
    }
    if (!empty($element['error'])) {
        $result .= '<div class="errmsg">' . Pieform::hsc($element['error']) . '</div>';
    }
    $result .= "</div>\n";
    return $result;
}
开发者ID:Br3nda,项目名称:mahara,代码行数:39,代码来源:div.php

示例8: pieform_element_radio

/**
 * Renders a set of radio buttons for a form
 *
 * @param array    $element The element to render
 * @param Pieform  $form    The form to render the element for
 * @return string           The HTML for the element
 */
function pieform_element_radio(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) {
        throw new PieformException('Radio elements should have at least one option');
    }
    $result = '';
    $form_value = $form->get_value($element);
    $id = $element['id'];
    $separator = "\n";
    if (isset($element['separator'])) {
        $separator = $element['separator'] . $separator;
    }
    foreach ($element['options'] as $value => $data) {
        $uid = $id . substr(md5(microtime()), 0, 4);
        $element['id'] = $uid;
        if (is_array($data)) {
            $text = $data['text'];
            $description = isset($data['description']) ? $data['description'] : '';
        } else {
            $text = $data;
            $description = '';
        }
        $result .= '<input type="radio"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($value) . '"' . ($form_value == $value ? ' checked="checked"' : '') . '> <label for="' . $form->get_name() . '_' . $uid . '">' . Pieform::hsc($text) . "</label>" . ($description != '' ? '<div class="radio-description">' . $description . '</div>' : '') . $separator;
    }
    $result = substr($result, 0, -strlen($separator));
    return $result;
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:35,代码来源:radio.php

示例9: pieform_renderer_oneline

/**
 * Renders form elements all on one line.
 *
 * @param Pieform $form    The form the element is being rendered for
 * @param array   $element The element that is being rendered
 * @return string          The element rendered inside an appropriate container
 */
function pieform_renderer_oneline(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    // Set the class of the enclosing <div> to match that of the element
    $result = '<span';
    if (isset($element['name'])) {
        $result .= ' id="' . $formname . '_' . Pieform::hsc($element['name']) . '_container"';
    }
    if (!empty($element['class'])) {
        $result .= ' class="' . Pieform::hsc($element['class']) . '"';
    }
    $result .= '>';
    if (isset($element['labelhtml'])) {
        $result .= $element['labelhtml'];
    }
    if (isset($element['prehtml'])) {
        $result .= '<span class="prehtml">' . $element['prehtml'] . '</span>';
    }
    $result .= $element['html'];
    if (isset($element['posthtml'])) {
        $result .= '<span class="posthtml">' . $element['posthtml'] . '</span>';
    }
    $result .= "</span>";
    return $result;
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:33,代码来源:oneline.php

示例10: pieform_element_calendar

/**
 * Provides a javascript calendar for inputting a date.
 *
 * General documentation about the calendar is available at
 * http://www.dynarch.com/static/jscalendar-1.0/doc/html/reference.html
 *
 * @param Pieform $form    The form to render the element for
 * @param array   $element The element to render
 * @return string          The HTML for the element
 */
function pieform_element_calendar(Pieform $form, $element)
{
    /*{{{*/
    $id = $form->get_name() . '_' . $element['name'];
    $value = $form->get_value($element);
    if ($value) {
        $value = Pieform::hsc(strftime($element['caloptions']['ifFormat'], $value));
    }
    // Build the HTML
    $result = '<input type="text"' . $form->element_attributes($element) . ' value="' . $value . '">';
    if (isset($element['imagefile'])) {
        $result .= '<a href="" id="' . $id . '_btn" onclick="return false;" class="pieform-calendar-toggle"' . ' tabindex="' . $element['tabindex'] . '">' . '<img src="' . $element['imagefile'] . '" alt=""></a>';
    } else {
        $result .= '<input type="button" id="' . $id . '_btn" onclick="return false;" class="pieform-calendar-toggle"' . ' value="..." tabindex="' . $element['tabindex'] . '">';
    }
    // Build the configuring javascript
    $options = array_merge($element['caloptions'], array('inputField' => $id, 'button' => $id . '_btn'));
    $encodedoptions = json_encode($options);
    // Some options are callbacks and need their quoting removed
    foreach (array('dateStatusFunc', 'flatCallback', 'onSelect', 'onClose', 'onUpdate') as $function) {
        $encodedoptions = preg_replace('/("' . $function . '"):"([a-zA-Z0-9$]+)"/', '\\1:\\2', $encodedoptions);
    }
    $result .= '<script type="text/javascript">Calendar.setup(' . $encodedoptions . ');</script>';
    return $result;
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:35,代码来源:calendar.php

示例11: pieform_renderer_oneline

/**
 * Renders form elements all on one line.
 *
 * @param Pieform $form    The form the element is being rendered for
 * @param array   $element The element that is being rendered
 * @return string          The element rendered inside an appropriate container
 */
function pieform_renderer_oneline(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    // Set the class of the enclosing <div> to match that of the element
    $result = '<span';
    if (isset($element['name'])) {
        $result .= ' id="' . $formname . '_' . $element['name'] . '_container"';
    }
    if (!empty($element['class'])) {
        $result .= ' class="' . $element['class'] . '"';
    }
    $result .= '>';
    if (isset($element['title']) && $element['title'] !== '' && $element['type'] != 'fieldset') {
        if (!empty($element['nolabel'])) {
            // Don't bother with a label for the element
            $result .= Pieform::hsc($element['title']);
        } else {
            $result .= '<label for="' . $element['id'] . '">' . Pieform::hsc($element['title']) . '</label>';
        }
        if ($form->get_property('requiredmarker') && !empty($element['rules']['required'])) {
            $result .= ' <span class="requiredmarker">*</span>';
        }
    }
    $result .= $element['html'];
    $result .= "</span>";
    return $result;
}
开发者ID:Br3nda,项目名称:mahara,代码行数:35,代码来源:oneline.php

示例12: pieform_element_submit

/**
 * Renders a submit button
 *
 * @param Pieform  $form    The form to render the element for
 * @param array    $element The element to render
 * @return string           The HTML for the element
 */
function pieform_element_submit(Pieform $form, $element)
{
    /*{{{*/
    if (isset($element['confirm'])) {
        $element['onclick'] = 'return confirm(' . json_encode($element['confirm']) . ');';
    }
    return '<input type="submit"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">';
}
开发者ID:Br3nda,项目名称:mahara,代码行数:15,代码来源:submit.php

示例13: pieform_element_button

/**
 * Renders an <input type="button"> element.
 *
 * The element must have the 'value' field set.
 *
 * @param Pieform $form    The form to render the element for
 * @param array   $element The element to render
 * @return string          The HTML for the element
 * @todo rename to inputbutton
 */
function pieform_element_button(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['value'])) {
        throw new PieformException('Button elements must have a value');
    }
    return '<input type="button"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($element['value']) . '">';
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:18,代码来源:button.php

示例14: pieform_element_fieldset

/**
 * Renders a fieldset. Fieldsets contain other elements, and do not count as a
 * "true" element, in that they do not have a value and cannot be validated.
 *
 * @param Pieform $form    The form to render the element for
 * @param array   $element The element to render
 * @return string          The HTML for the element
 */
function pieform_element_fieldset(Pieform $form, $element)
{
    /*{{{*/
    global $_PIEFORM_FIELDSETS;
    $result = "\n<fieldset";
    if (!empty($element['collapsible']) || !empty($element['class'])) {
        if (!isset($element['legend']) || $element['legend'] === '') {
            Pieform::info('Collapsible fieldsets should have a legend so they can be toggled');
        }
        $classes = array('collapsible');
        $formname = $form->get_name();
        if (!isset($_PIEFORM_FIELDSETS['forms'][$formname])) {
            $_PIEFORM_FIELDSETS['forms'][$formname] = array('formname' => $formname);
        }
        // Work out whether any of the children have errors on them
        $error = false;
        foreach ($element['elements'] as $subelement) {
            if (isset($subelement['error'])) {
                $error = true;
                break;
            }
        }
        if (!empty($element['collapsed']) && !$error) {
            $classes[] = 'collapsed';
        }
        if (!empty($element['class'])) {
            $classes[] = Pieform::hsc($element['class']);
        }
        $result .= ' class="' . implode(' ', $classes) . '"';
    }
    $result .= ">\n";
    if (isset($element['legend'])) {
        $result .= '<legend>';
        if (!empty($element['collapsible'])) {
            $result .= '<a href="">' . Pieform::hsc($element['legend']) . '</a>';
        } else {
            $result .= Pieform::hsc($element['legend']);
        }
        // Help icon
        if (!empty($element['help'])) {
            $function = $form->get_property('helpcallback');
            if (function_exists($function)) {
                $result .= $function($form, $element);
            } else {
                $result .= '<span class="help"><a href="" title="' . Pieform::hsc($element['help']) . '" onclick="return false;">?</a></span>';
            }
        }
        $result .= "</legend>\n";
    }
    foreach ($element['elements'] as $subname => $subelement) {
        if ($subelement['type'] == 'hidden') {
            throw new PieformError("You cannot put hidden elements in fieldsets");
        }
        $result .= "\t" . pieform_render_element($form, $subelement);
    }
    $result .= "</fieldset>\n";
    return $result;
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:66,代码来源:fieldset.php

示例15: pieform_element_file

/**
 * Renders a basic HTML <input type="file"> element.
 *
 * @param Pieform $form    The form to render the element for
 * @param array   $element The element to render
 * @return string           The HTML for the element
 */
function pieform_element_file(Pieform $form, $element)
{
    /*{{{*/
    $result = '';
    if (isset($element['maxfilesize']) && is_int($element['maxfilesize'])) {
        $result = '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element['maxfilesize'] . '"/>';
    }
    $result .= '<input type="file"' . $form->element_attributes($element) . (isset($element['accept']) ? ' accept="' . Pieform::hsc($element['accept']) . '"' : '') . '>';
    return $result;
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:17,代码来源:file.php


注:本文中的Pieform::hsc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。