<commit_before><?php

namespace Frontend\Core\Engine;

/*
 * This file is part of Fork CMS.
 *
 * For the full copyright and license information, please view the license
 * file that was distributed with this source code.
 */

use Symfony\Component\Filesystem\Filesystem;

use Frontend\Core\Engine\Language AS FL;


/**
 * This is our extended version of SpoonForm.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class Form extends \SpoonForm
{
    /**
     * The header instance
     *
     * @var    Header
     */
    private $header;

    /**
     * The URL instance
     *
     * @var    Url
     */
    private $URL;

    /**
     * @param string $name     Name of the form.
     * @param string $action   The action (URL) whereto the form will be submitted, if not provided it will
     *                         be auto generated.
     * @param string $method   The method to use when submitting the form, default is POST.
     * @param string $hash     The id of the anchor to append to the action-URL.
     * @param bool   $useToken Should we automagically add a form token?
     */
    public function __construct($name, $action = null, $method = 'post', $hash = null, $useToken = true)
    {
        $this->URL = Model::getContainer()->get('url');
        $this->header = Model::getContainer()->get('header');

        $name = (string) $name;

        if ($hash !== null && strlen($hash) > 0) {
            $hash = (string) $hash;
            // check if the # is present
            if ($hash[0] !== '#') {
                $hash = '#' . $hash;
            }
        } else {
            $hash = null;
        }

        $useToken = (bool) $useToken;
        $action = ($action === null) ? '/' . $this->URL->getQueryString() : (string) $action;

        // call the real form-class
        parent::__construct((string) $name, $action . $hash, $method, (bool) $useToken);

        // add default classes
        $this->setParameter('id', $name);
        $this->setParameter('class', 'forkForms submitWithLink');
    }

    /**
     * Adds a button to the form
     *
     * @param string $name  Name of the button.
     * @param string $value The value (or label) that will be printed.
     * @param string $type  The type of the button (submit is default).
     * @param string $class Class(es) that will be applied on the button.
     * @return \SpoonFormButton
     */
    public function addButton($name, $value, $type = 'submit', $class = null)
    {
        $name = (string) $name;
        $value = (string) $value;
        $type = (string) $type;
        $class = ($class !== null) ? (string) $class : 'inputText inputButton';

        // do a check, only enable this if we use forms that are submitted with javascript
        if ($type == 'submit' && $name == 'submit') {
            throw new Exception(
                'You can\'t add buttons with the name submit. JS freaks out
                when we replace the buttons with a link and use that link to
                submit the form.'
            );
        }

        // create and return a button
        return parent::addButton($name, $value, $type, $class);
    }

    /**
     * Adds a single checkbox.
     *
     * @param string $name       The name of the element.
     * @param bool   $checked    Should the checkbox be checked?
     * @param string $class      Class(es) that will be applied on the element.
     * @param string $classError Class(es) that will be applied on the element when an error occurs.
     * @return \SpoonFormCheckbox
     */
    public function addCheckbox($name, $checked = false, $class = null, $classError = null)
    {
        $name = (string) $name;
        $checked = (bool) $checked;
        $class = ($class !== null) ? (string) $class : 'inputCheckbox';
        $classError = ($classError !== null) ? (string) $classError : 'inputCheckboxError';

        // create and return a checkbox
        return parent::addCheckbox($name, $checked, $class, $classError);
    }

    /**
     * Adds a date field to the form
     *
     * @param string $name       Name of the element.
     * @param mixed  $value      The value for the element.
     * @param string $type       The type (from, till, range) of the datepicker.
     * @param int    $date       The date to use.
     * @param int    $date2      The second date for a rangepicker.
     * @param string $class      Class(es) that have to be applied on the element.
     * @param string $classError Class(es) that have to be applied when an error occurs on the element.
     * @return FrontendFormDate
     */
    public function addDate(
        $name,
        $value = null,
        $type = null,
        $date = null,
        $date2 = null,
        $class = null,
        $classError = null
    ) {
        $name = (string) $name;
        $value = ($value !== null) ? (($value !== '') ? (int) $value : '') : null;
        $type = \SpoonFilter::getValue($type, array('from', 'till', 'range'), 'none');
        $date = ($date !== null) ? (int) $date : null;
        $date2 = ($date2 !== null) ? (int) $date2 : null;
        $class = ($class !== null) ? (string) $class : 'inputText inputDate';
        $classError = ($classError !== null) ? (string) $classError : 'inputTextError inputDateError';

        // validate
        if ($type == 'from' && ($date == 0 || $date == null)) {
            throw new Exception('A date field with type "from" should have a valid date-parameter.');
        }
        if ($type == 'till' && ($date == 0 || $date == null)) {
            throw new Exception('A date field with type "till" should have a valid date-parameter.');
        }
        if ($type == 'range' && ($date == 0 || $date2 == 0 || $date == null || $date2 == null)) {
            throw new Exception('A date field with type "range" should have 2 valid date-parameters.');
        }

        // @later	get preferred mask & first day
        $mask = 'd/m/Y';
        $firstDay = 1;

        // build attributes
        $attributes['data-mask'] = str_replace(
            array('d', 'm', 'Y', 'j', 'n'),
            array('dd', 'mm', 'yy', 'd', 'm'),
            $mask<commit_msg>Fixes #1174, use date_format_short from settings to format SpoonForm addDate.<commit_after><?php

namespace Frontend\Core\Engine;

/*
 * This file is part of Fork CMS.
 *
 * For the full copyright and license information, please view the license
 * file that was distributed with this source code.
 */

use Symfony\Component\Filesystem\Filesystem;

use Frontend\Core\Engine\Language AS FL;


/**
 * This is our extended version of SpoonForm.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class Form extends \SpoonForm
{
    /**
     * The header instance
     *
     * @var    Header
     */
    private $header;

    /**
     * The URL instance
     *
     * @var    Url
     */
    private $URL;

    /**
     * @param string $name     Name of the form.
     * @param string $action   The action (URL) whereto the form will be submitted, if not provided it will
     *                         be auto generated.
     * @param string $method   The method to use when submitting the form, default is POST.
     * @param string $hash     The id of the anchor to append to the action-URL.
     * @param bool   $useToken Should we automagically add a form token?
     */
    public function __construct($name, $action = null, $method = 'post', $hash = null, $useToken = true)
    {
        $this->URL = Model::getContainer()->get('url');
        $this->header = Model::getContainer()->get('header');

        $name = (string) $name;

        if ($hash !== null && strlen($hash) > 0) {
            $hash = (string) $hash;
            // check if the # is present
            if ($hash[0] !== '#') {
                $hash = '#' . $hash;
            }
        } else {
            $hash = null;
        }

        $useToken = (bool) $useToken;
        $action = ($action === null) ? '/' . $this->URL->getQueryString() : (string) $action;

        // call the real form-class
        parent::__construct((string) $name, $action . $hash, $method, (bool) $useToken);

        // add default classes
        $this->setParameter('id', $name);
        $this->setParameter('class', 'forkForms submitWithLink');
    }

    /**
     * Adds a button to the form
     *
     * @param string $name  Name of the button.
     * @param string $value The value (or label) that will be printed.
     * @param string $type  The type of the button (submit is default).
     * @param string $class Class(es) that will be applied on the button.
     * @return \SpoonFormButton
     */
    public function addButton($name, $value, $type = 'submit', $class = null)
    {
        $name = (string) $name;
        $value = (string) $value;
        $type = (string) $type;
        $class = ($class !== null) ? (string) $class : 'inputText inputButton';

        // do a check, only enable this if we use forms that are submitted with javascript
        if ($type == 'submit' && $name == 'submit') {
            throw new Exception(
                'You can\'t add buttons with the name submit. JS freaks out
                when we replace the buttons with a link and use that link to
                submit the form.'
            );
        }

        // create and return a button
        return parent::addButton($name, $value, $type, $class);
    }

    /**
     * Adds a single checkbox.
     *
     * @param string $name       The name of the element.
     * @param bool   $checked    Should the checkbox be checked?
     * @param string $class      Class(es) that will be applied on the element.
     * @param string $classError Class(es) that will be applied on the element when an error occurs.
     * @return \SpoonFormCheckbox
     */
    public function addCheckbox($name, $checked = false, $class = null, $classError = null)
    {
        $name = (string) $name;
        $checked = (bool) $checked;
        $class = ($class !== null) ? (string) $class : 'inputCheckbox';
        $classError = ($classError !== null) ? (string) $classError : 'inputCheckboxError';

        // create and return a checkbox
        return parent::addCheckbox($name, $checked, $class, $classError);
    }

    /**
     * Adds a date field to the form
     *
     * @param string $name       Name of the element.
     * @param mixed  $value      The value for the element.
     * @param string $type       The type (from, till, range) of the datepicker.
     * @param int    $date       The date to use.
     * @param int    $date2      The second date for a rangepicker.
     * @param string $class      Class(es) that have to be applied on the element.
     * @param string $classError Class(es) that have to be applied when an error occurs on the element.
     * @return FrontendFormDate
     */
    public function addDate(
        $name,
        $value = null,
        $type = null,
        $date = null,
        $date2 = null,
        $class = null,
        $classError = null
    ) {
        $name = (string) $name;
        $value = ($value !== null) ? (($value !== '') ? (int) $value : '') : null;
        $type = \SpoonFilter::getValue($type, array('from', 'till', 'range'), 'none');
        $date = ($date !== null) ? (int) $date : null;
        $date2 = ($date2 !== null) ? (int) $date2 : null;
        $class = ($class !== null) ? (string) $class : 'inputText inputDate';
        $classError = ($classError !== null) ? (string) $classError : 'inputTextError inputDateError';

        // validate
        if ($type == 'from' && ($date == 0 || $date == null)) {
            throw new Exception('A date field with type "from" should have a valid date-parameter.');
        }
        if ($type == 'till' && ($date == 0 || $date == null)) {
            throw new Exception('A date field with type "till" should have a valid date-parameter.');
        }
        if ($type == 'range' && ($date == 0 || $date2 == 0 || $date == null || $date2 == null)) {
            throw new Exception('A date field with type "range" should have 2 valid date-parameters.');
        }

        // set mask and firstday
        $mask = Model::get('fork.settings')->get('Core', 'date_format_short');
        $firstDay = 1;

        // build attributes
        $attributes['data-mask'] = str_replace(
            array('d', 'm', 'Y', 'j', 'n'),
            array('dd', 'mm', 'yy', 'd', 'm'),
            $mask
{'fraction_non_alphanumeric': 0.138732507640341, 'fraction_numerical': 0.0027344378317516486, 'mean_word_length': 2.094053247076387, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 34, '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': '6254563', 'n_tokens_mistral': 3621, 'n_tokens_neox': 3544, 'n_words': 1287}