<commit_before><?php

/**
 * Form parser and generic form handlers.
 *
 * @access public
 * @module form
 * @package User interface
 */


# Copyright (c) 2000-2002 dev/consulting GmbH
# Copyright (c) 2011 <NAME> <<EMAIL>>
#
# Licensed under the MIT, BSD and GPL licenses.


function _formviews_init (&$app)
{
    $e = array ('form_parser', 'form_update', 'form_create', 'form_safe', 'form_check');
    util_add_raw_functions ($app, $e);
}

/**
 * Collect and sort form elements and fetch uploaded files.
 *
 * @access private
 * @param object application $app Reference to current application.
 * @param array $forms            Form elements sorted by form index.
 * @param array $formevents       Form functions, keyed by form index.
 * @param array $filteredelements Elements that need filtering. 
 */
function _form_collect (&$app, &$forms, &$formevents, &$filteredelements)
{
    $item = $_POST['item'];

    # Sort elements by form function and read the token data.
    if (!isset ($item) || !is_array ($item))
        die ('No form content to process.');

    $forms = array ();
    $formevents = array ();
    $filteredelements = array();
    foreach ($item as $token => $v) {
        # Unserialise _form_element object.
        $e = $app->_tokens->get ($token);
        # Store form function specified by submit button.
        if ($e->is_submit) {
            # TODO: Multiple form functions (only first element is used).
            $formevents[$e->form_idx] = $e->view;
            continue;
        } else if (!isset ($formevents[$e->form_idx]) && $e->defaultfunc)
            $formevents[$e->form_idx] = $e->defaultfunc;

        # Get file upload.
        # See also $ui->filelink ().
        if ($field = $e->is_file) {
            # Skip entry if file info is incomplete.
            if (!isset ($GLOBALS[$field])
                || ($file = $GLOBALS[$field]) == 'none'
                || !($size = $GLOBALS[$field . '_size'])
                || !($name = $GLOBALS[$field . '_name']))
                continue;

            # Read in transmitted file.
            $f = fopen ($file, 'r');
            $v = fread ($f, $size);
            fclose ($f);

            $e->filename = $name;
            $e->file = $file;
        }

        $e->val = $v;

        # Schedule element for run through filter function.
        if ($e->use_filter) {
            $filter = $e->use_filter;
            $formfilter[$filter->name] = $e;
            $filteredelements[$filter][$token] = $e;
        }

        $forms[$e->form_idx][$token] = $e;
    }<commit_msg>Fix collecting elements for form filter.<commit_after><?php

/**
 * Form parser and generic form handlers.
 *
 * @access public
 * @module form
 * @package User interface
 */


# Copyright (c) 2000-2002 dev/consulting GmbH
# Copyright (c) 2011 <NAME> <<EMAIL>>
#
# Licensed under the MIT, BSD and GPL licenses.


function _formviews_init (&$app)
{
    $e = array ('form_parser', 'form_update', 'form_create', 'form_safe', 'form_check');
    util_add_raw_functions ($app, $e);
}

/**
 * Collect and sort form elements and fetch uploaded files.
 *
 * @access private
 * @param object application $app Reference to current application.
 * @param array $forms            Form elements sorted by form index.
 * @param array $formevents       Form functions, keyed by form index.
 * @param array $filteredelements Elements that need filtering. 
 */
function _form_collect (&$app, &$forms, &$formevents, &$filteredelements)
{
    $item = $_POST['item'];

    # Sort elements by form function and read the token data.
    if (!isset ($item) || !is_array ($item))
        die ('No form content to process.');

    $forms = array ();
    $formevents = array ();
    $filteredelements = array();
    foreach ($item as $token => $v) {
        # Unserialise _form_element object.
        $e = $app->_tokens->get ($token);
        # Store form function specified by submit button.
        if ($e->is_submit) {
            # TODO: Multiple form functions (only first element is used).
            $formevents[$e->form_idx] = $e->view;
            continue;
        } else if (!isset ($formevents[$e->form_idx]) && $e->defaultfunc)
            $formevents[$e->form_idx] = $e->defaultfunc;

        # Get file upload.
        # See also $ui->filelink ().
        if ($field = $e->is_file) {
            # Skip entry if file info is incomplete.
            if (!isset ($GLOBALS[$field])
                || ($file = $GLOBALS[$field]) == 'none'
                || !($size = $GLOBALS[$field . '_size'])
                || !($name = $GLOBALS[$field . '_name']))
                continue;

            # Read in transmitted file.
            $f = fopen ($file, 'r');
            $v = fread ($f, $size);
            fclose ($f);

            $e->filename = $name;
            $e->file = $file;
        }

        $e->val = $v;

        # Schedule element for run through filter function.
        if ($e->use_filter) {
            $filter = $e->use_filter;
            $formfilter[$filter] = $e;
            $filteredelements[$filter][$token] = $e;
        }

        $forms[$e->form_idx][$token] = $e;
    }
{'fraction_non_alphanumeric': 0.14985422740524781, 'fraction_numerical': 0.004664723032069971, 'mean_word_length': 2.228356336260979, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4520641', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1474, 'n_words': 463}