Classes

File builder/form/field/constraint/FormFieldConstraintMaxLinks.class.php

File builder/form/field/constraint/FormFieldConstraintMaxLinks.class.php

 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 
<?php
/**
 * @package     Builder
 * @subpackage  Form\field\constraint
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Kevin MASSY <reidlos@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2014 12 22
 * @since       PHPBoost 3.0 - 2011 03 13
*/

class FormFieldConstraintMaxLinks extends AbstractFormFieldConstraint
{
    private $number_links_authorized;
    private $has_html_content;

    /**
     * @param int $number_links_authorized
     * @param bool $has_html_links true if the content is in HTML
     * @param string $error_message
     */
    public function __construct($number_links_authorized, $has_html_links = false, $error_message = '')
    {
        $this->number_links_authorized = $number_links_authorized;
        $this->has_html_links = $has_html_links;

        if (empty($error_message))
        {
            $error_message = sprintf(LangLoader::get_message('e_l_flood', 'errors'), $this->number_links_authorized);
        }
        $this->set_validation_error_message($error_message);
    }

    public function validate(FormField $field)
    {
        return $this->exceeding_links($field);
    }

    public function get_js_validation(FormField $field)
    {
        return '';
    }

    public function exceeding_links($field)
    {
        return TextHelper::check_nbr_links($field->get_value(), $this->number_links_authorized, $this->has_html_links);
    }
}

?>