[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/components/com_contact/src/Rule/ -> ContactEmailMessageRule.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  com_contact
   6   *
   7   * @copyright   (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Contact\Site\Rule;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\Form\Form;
  15  use Joomla\CMS\Form\FormRule;
  16  use Joomla\Registry\Registry;
  17  use Joomla\String\StringHelper;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * FormRule for com_contact to make sure the message body contains no banned word.
  25   *
  26   * @since  1.6
  27   */
  28  class ContactEmailMessageRule extends FormRule
  29  {
  30      /**
  31       * Method to test a message for banned words
  32       *
  33       * @param   \SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  34       * @param   mixed              $value    The form field value to validate.
  35       * @param   string             $group    The field name group control value. This acts as an array container for the field.
  36       *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  37       *                                       full field name would end up being "bar[foo]".
  38       * @param   Registry           $input    An optional Registry object with the entire data set to validate against the entire form.
  39       * @param   Form               $form     The form object for which the field is being tested.
  40       *
  41       * @return  boolean  True if the value is valid, false otherwise.
  42       */
  43      public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
  44      {
  45          $params = ComponentHelper::getParams('com_contact');
  46          $banned = $params->get('banned_text');
  47  
  48          if ($banned) {
  49              foreach (explode(';', $banned) as $item) {
  50                  if ($item != '' && StringHelper::stristr($value, $item) !== false) {
  51                      return false;
  52                  }
  53              }
  54          }
  55  
  56          return true;
  57      }
  58  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer