File indexing completed on 2025-01-26 05:29:11
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 * 0023 * Created: 23.06.2017 0024 */ 0025 class Local_Markup_Parser_BbcodeCI extends Zend_Markup_Parser_Bbcode 0026 { 0027 /** 0028 * @inheritDoc 0029 */ 0030 protected function _tokenize() 0031 { 0032 $attribute = ''; 0033 0034 while ($this->_pointer < $this->_valueLen) { 0035 switch ($this->_state) { 0036 case self::STATE_SCAN: 0037 $matches = array(); 0038 $regex = '#\G(?<text>[^\[]*)(?<open>\[(?<name>[' . self::NAME_CHARSET . ']+)?)?#'; 0039 preg_match($regex, $this->_value, $matches, null, $this->_pointer); 0040 0041 $this->_pointer += strlen($matches[0]); 0042 0043 if (!empty($matches['text'])) { 0044 $this->_buffer .= $matches['text']; 0045 } 0046 0047 if (!isset($matches['open'])) { 0048 // great, no tag, we are ending the string 0049 break; 0050 } 0051 if (!isset($matches['name'])) { 0052 $this->_buffer .= $matches['open']; 0053 break; 0054 } 0055 0056 $this->_temp = array( 0057 'tag' => '[' . strtolower($matches['name']), 0058 'name' => strtolower($matches['name']), 0059 'attributes' => array() 0060 ); 0061 0062 if ($this->_pointer >= $this->_valueLen) { 0063 // damn, no tag 0064 $this->_buffer .= $this->_temp['tag']; 0065 break 2; 0066 } 0067 0068 if ($this->_value[$this->_pointer] == '=') { 0069 $this->_pointer++; 0070 0071 $this->_temp['tag'] .= '='; 0072 $this->_state = self::STATE_PARSEVALUE; 0073 $attribute = $this->_temp['name']; 0074 } else { 0075 $this->_state = self::STATE_SCANATTRS; 0076 } 0077 break; 0078 case self::STATE_SCANATTRS: 0079 $matches = array(); 0080 $regex = '#\G((?<end>\s*\])|\s+(?<attribute>[' . self::NAME_CHARSET . ']+)(?<eq>=?))#'; 0081 if (!preg_match($regex, $this->_value, $matches, null, $this->_pointer)) { 0082 break 2; 0083 } 0084 0085 $this->_pointer += strlen($matches[0]); 0086 0087 if (!empty($matches['end'])) { 0088 if (!empty($this->_buffer)) { 0089 $this->_tokens[] = array( 0090 'tag' => $this->_buffer, 0091 'type' => Zend_Markup_Token::TYPE_NONE 0092 ); 0093 $this->_buffer = ''; 0094 } 0095 $this->_temp['tag'] .= $matches['end']; 0096 $this->_temp['type'] = Zend_Markup_Token::TYPE_TAG; 0097 0098 $this->_tokens[] = $this->_temp; 0099 $this->_temp = array(); 0100 0101 $this->_state = self::STATE_SCAN; 0102 } else { 0103 // attribute name 0104 $attribute = $matches['attribute']; 0105 0106 $this->_temp['tag'] .= $matches[0]; 0107 0108 $this->_temp['attributes'][$attribute] = ''; 0109 0110 if (empty($matches['eq'])) { 0111 $this->_state = self::STATE_SCANATTRS; 0112 } else { 0113 $this->_state = self::STATE_PARSEVALUE; 0114 } 0115 } 0116 break; 0117 case self::STATE_PARSEVALUE: 0118 $matches = array(); 0119 $regex = '#\G((?<quote>"|\')(?<valuequote>.*?)\\2|(?<value>[^\]\s]+))#'; 0120 if (!preg_match($regex, $this->_value, $matches, null, $this->_pointer)) { 0121 $this->_state = self::STATE_SCANATTRS; 0122 break; 0123 } 0124 0125 $this->_pointer += strlen($matches[0]); 0126 0127 if (!empty($matches['quote'])) { 0128 $this->_temp['attributes'][$attribute] = $matches['valuequote']; 0129 } else { 0130 $this->_temp['attributes'][$attribute] = $matches['value']; 0131 } 0132 $this->_temp['tag'] .= $matches[0]; 0133 0134 $this->_state = self::STATE_SCANATTRS; 0135 break; 0136 } 0137 } 0138 0139 if (!empty($this->_buffer)) { 0140 $this->_tokens[] = array( 0141 'tag' => $this->_buffer, 0142 'type' => Zend_Markup_Token::TYPE_NONE 0143 ); 0144 } 0145 } 0146 0147 }