Esempio n. 1
0
 /**
  * Check the field's settings to ensure they are valid on the section
  * editor
  *
  * @param array $errors
  *	the array to populate with the errors found.
  * @param boolean $checkForDuplicates (optional)
  *	if set to true, duplicate Field name's in the same section will be flagged
  *  as errors. Defaults to true.
  * @return integer
  *	returns the status of the checking. if errors has been populated with
  *	any errors `self::__ERROR__`, `self::__OK__` otherwise.
  */
 public function checkFields(array &$errors, $checkForDuplicates = true)
 {
     $parent_section = $this->get('parent_section');
     $element_name = $this->get('element_name');
     if (Lang::isUnicodeCompiled()) {
         $valid_name = preg_match('/^[\\p{L}]([0-9\\p{L}\\.\\-\\_]+)?$/u', $this->get('element_name'));
     } else {
         $valid_name = preg_match('/^[A-z]([\\w\\d-_\\.]+)?$/i', $this->get('element_name'));
     }
     if ($this->get('label') == '') {
         $errors['label'] = __('This is a required field.');
     }
     if ($this->get('element_name') == '') {
         $errors['element_name'] = __('This is a required field.');
     } elseif (!$valid_name) {
         $errors['element_name'] = __('Invalid element name. Must be valid %s.', array('<code>QName</code>'));
     } elseif ($checkForDuplicates) {
         if (FieldManager::fetchFieldIDFromElementName($element_name, $parent_section) != $this->get('id')) {
             $errors['element_name'] = __('A field with that element name already exists. Please choose another.');
         }
     }
     return !empty($errors) ? self::__ERROR__ : self::__OK__;
 }
Esempio n. 2
0
 /**
  * Check the field's settings to ensure they are valid on the section
  * editor
  *
  * @param array $errors
  *	the array to populate with the errors found.
  * @param boolean $checkForDuplicates (optional)
  *	if set to true, duplicate Field name's in the same section will be flagged
  *  as errors. Defaults to true.
  * @return integer
  *	returns the status of the checking. if errors has been populated with
  *	any errors `self::__ERROR__`, `self::__OK__` otherwise.
  */
 public function checkFields(array &$errors, $checkForDuplicates = true)
 {
     $parent_section = $this->get('parent_section');
     $element_name = $this->get('element_name');
     if (Lang::isUnicodeCompiled()) {
         $valid_name = preg_match('/^[\\p{L}]([0-9\\p{L}\\.\\-\\_]+)?$/u', $this->get('element_name'));
     } else {
         $valid_name = preg_match('/^[A-z]([\\w\\d-_\\.]+)?$/i', $this->get('element_name'));
     }
     if ($this->get('label') == '') {
         $errors['label'] = __('This is a required field.');
     }
     if ($this->get('element_name') == '') {
         $errors['element_name'] = __('This is a required field.');
     } elseif (!$valid_name) {
         $errors['element_name'] = __('Invalid element name. Must be valid QName.');
     } elseif ($checkForDuplicates) {
         $sql_id = $this->get('id') ? " AND f.id != '" . $this->get('id') . "' " : '';
         $sql = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tf.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_fields` AS f\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tf.element_name = '{$element_name}'\n\t\t\t\t\t\t{$sql_id}\n\t\t\t\t\t\tAND f.parent_section = '{$parent_section}'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t";
         if (Symphony::Database()->fetchRow(0, $sql)) {
             $errors['element_name'] = __('A field with that element name already exists. Please choose another.');
         }
     }
     return !empty($errors) ? self::__ERROR__ : self::__OK__;
 }
Esempio n. 3
0
 /**
  * This function strips characters that are not allowed in XML
  *
  * @since Symphony 2.3
  * @link http://www.w3.org/TR/xml/#charsets
  * @link http://www.phpedit.net/snippet/Remove-Invalid-XML-Characters
  * @param string $value
  * @return string
  */
 public static function stripInvalidXMLCharacters($value)
 {
     if (Lang::isUnicodeCompiled()) {
         return preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', ' ', $value);
     } else {
         $ret = '';
         if (empty($value)) {
             return $ret;
         }
         $length = strlen($value);
         for ($i = 0; $i < $length; $i++) {
             $current = ord($value[$i]);
             if ($current == 0x9 || $current == 0xa || $current == 0xd || $current >= 0x20 && $current <= 0xd7ff || $current >= 0xe000 && $current <= 0xfffd || $current >= 0x10000 && $current <= 0x10ffff) {
                 $ret .= chr($current);
             }
         }
         return $ret;
     }
 }
Esempio n. 4
0
 /**
  * Check the field's settings to ensure they are valid on the section
  * editor
  *
  * @param array $errors
  *  the array to populate with the errors found.
  * @param boolean $checkForDuplicates (optional)
  *  if set to true, duplicate Field name's in the same section will be flagged
  *  as errors. Defaults to true.
  * @return integer
  *  returns the status of the checking. if errors has been populated with
  *  any errors `self::__ERROR__`, `self::__OK__` otherwise.
  */
 public function checkFields(array &$errors, $checkForDuplicates = true)
 {
     $parent_section = $this->get('parent_section');
     $label = $this->get('label');
     $element_name = $this->get('element_name');
     if (Lang::isUnicodeCompiled()) {
         $valid_name = preg_match('/^[\\p{L}]([0-9\\p{L}\\.\\-\\_]+)?$/u', $element_name);
     } else {
         $valid_name = preg_match('/^[A-z]([\\w\\d-_\\.]+)?$/i', $element_name);
     }
     if ($label === '') {
         $errors['label'] = __('This is a required field.');
     } elseif (strtolower($label) === 'id') {
         $errors['label'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>ID</code>', '<code>UID</code>'));
     }
     if ($element_name === '') {
         $errors['element_name'] = __('This is a required field.');
     } elseif ($element_name === 'id') {
         $errors['element_name'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>id</code>', '<code>uid</code>'));
     } elseif (!$valid_name) {
         $errors['element_name'] = __('Invalid element name. Must be valid %s.', array('<code>QName</code>'));
     } elseif ($checkForDuplicates) {
         if (FieldManager::fetchFieldIDFromElementName($element_name, $parent_section) !== $this->get('id')) {
             $errors['element_name'] = __('A field with that element name already exists. Please choose another.');
         }
     }
     // Check that if the validator is provided that it's a valid regular expression
     if (!is_null($this->get('validator')) && $this->get('validator') !== '') {
         if (@preg_match($this->get('validator'), 'teststring') === false) {
             $errors['validator'] = __('Validation rule is not a valid regular expression');
         }
     }
     return !empty($errors) ? self::__ERROR__ : self::__OK__;
 }
Esempio n. 5
0
 /**
  * This function takes a string and returns an empty DOMElement
  * with a valid name. If the passed `$name` is a valid QName, the handle of
  * this name will be the name of the element, otherwise this will fallback to 'key'.
  *
  * @see toolkit.Lang#createHandle
  * @param string $name
  *  If the `$name` is not a valid QName it will be ignored and replaced with
  *  'key'. If this happens, a `@value` attribute will be set with the original
  *  `$name`. If `$name` is a valid QName, it will be run through `Lang::createHandle`
  *  to create a handle for the element.
  * @return DOMElement
  *  An empty DOMElement with `@handle` and `@value` attributes.
  */
 private static function _valid_element_name($name)
 {
     if (Lang::isUnicodeCompiled()) {
         $valid_name = preg_match('/^[\\p{L}]([0-9\\p{L}\\.\\-\\_]+)?$/u', $name);
     } else {
         $valid_name = preg_match('/^[A-z]([\\w\\d-_\\.]+)?$/i', $name);
     }
     if ($valid_name) {
         $xKey = self::$dom->createElement(Lang::createHandle($name));
     } else {
         $xKey = self::$dom->createElement('key');
     }
     $xKey->setAttribute('handle', Lang::createHandle($name));
     $xKey->setAttribute('value', General::sanitize($name));
     return $xKey;
 }