Пример #1
0
 /**
  * 	Sprawdza i buduję listę parametrów taga na podstawie podanego tekstu
  * 	@param array $tagInfo tablica ustawień taga wyciągnięta z filtra bądź z {@link $tags}
  * 	@param string $text tekst z którego należy wyciągnąć atrybuty
  * 	@return mixed - false w przypadku braku atrybutów, -1 w przypadku brak wymaganych atrybutów, tablica parametrów w przypadku prawidłowego odczytania parametrów
  */
 private function _parseAttributes($tagInfo, $text)
 {
     $attr = $tagInfo['attributes'];
     // ustawienia atrybutów taga
     $tagAttributes = array();
     // atrybuty taga
     $text = substr($text, 1, -1);
     preg_match_all('/\\s*([a-z0-9-_]+)=(\'.+?\'|".+?"|\\S*)\\s*/i', $text, $matches, PREG_SET_ORDER);
     if (count($matches) == 0) {
         // nie ma wymaganego argumentu
         if (isset($tagInfo['required_attributes'])) {
             return -1;
         } elseif (isset($tagInfo['default_attributes'])) {
             foreach ($tagInfo['default_attributes'] as $attrName) {
                 $attrOptions = $tagInfo['attributes'][$attrName];
                 $this->_parseDefaultAttribute($attrName, $attrOptions, 'no_enter', $tagAttributes);
             }
             return $tagAttributes;
         } else {
             return false;
         }
     }
     foreach ($matches as $attribute) {
         $tagAttr = strtolower($attribute[1]);
         if (strlen($attribute[2]) == 0) {
             continue;
         }
         // jezelo koncza sie na ' lub " to trzeba to usunac
         $attribute[2] = trim($attribute[2], '"\'');
         /*
          if(in_array($attribute[2][0], array('\'', '"'))) $attribute[2]=substr($attribute[2],1);
          if(in_array($attribute[2][strlen($attribute[2])-1], array('\'', '"'))) $attribute[2]=substr($attribute[2],0, -1);
         */
         if (!$this->settings->trustText) {
             require_once dirname(__FILE__) . '/DataValidator.php';
             // sprawdzanie w liscie mozliwych atrybutow ale takze czy atrybut sie nei powtarza
             if (!isset($attr[$tagAttr]) || isset($tagAttributes[$tagAttr])) {
                 continue;
             }
             $options = $attr[$tagAttr];
             if (isset($options['no_changeable']) && $options['no_changeable']) {
                 continue;
             }
             switch ($options['type']) {
                 case 'number':
                     $str = @DataValidator::parseNumber($attribute[2], isset($options['dimensions']) ? $options['dimensions'] : null, isset($options['default_dimension']) ? $options['default_dimension'] : null, true);
                     break;
                 case 'url':
                     $str = @DataValidator::checkUrl($attribute[2]);
                     break;
                 default:
                 case 'string':
                     $str = @DataValidator::checkStringValues($attribute[2], isset($options['values']) ? $options['values'] : null, isset($options['replace']) ? $options['replace'] : null);
                     break;
             }
             if ($str == false && isset($tagInfo['default_attributes']) && in_array($tagAttr, $tagInfo['default_attributes'])) {
                 $this->_parseDefaultAttribute($tagAttr, $options, 'no_valid', $tagAttributes);
                 continue;
             } elseif ($str == false) {
                 continue;
             } else {
                 $str = htmlspecialchars($str);
             }
         } else {
             $str = $attribute[2];
         }
         $tagAttributes[$tagAttr] = $str;
     }
     if (isset($tagInfo['default_attributes'])) {
         foreach ($tagInfo['default_attributes'] as $dAttribute) {
             if (!isset($tagAttributes[$dAttribute])) {
                 $this->_parseDefaultAttribute($dAttribute, $tagInfo['attributes'][$dAttribute], 'no_enter', $tagAttributes);
             }
         }
     }
     if (isset($tagInfo['required_attributes'])) {
         //sprawdzanie czy wystapily wszystkie wymagane atrybuty
         foreach ($tagInfo['required_attributes'] as $rAttribute) {
             if (!isset($tagAttributes[$rAttribute])) {
                 return -1;
             }
         }
     }
     return $tagAttributes ? $tagAttributes : false;
 }