@@ -1108,47 +1108,16 @@ protected function replaceXmlBlock($macro, $block, $blockType = 'w:p')
1108
1108
protected function findContainingXmlBlockForMacro ($ macro , $ blockType = 'w:p ' )
1109
1109
{
1110
1110
$ macroPos = $ this ->findMacro ($ macro );
1111
- if (false === $ macroPos ) {
1111
+ if (0 > $ macroPos ) {
1112
1112
return false ;
1113
1113
}
1114
1114
$ start = $ this ->findXmlBlockStart ($ macroPos , $ blockType );
1115
1115
if (0 > $ start ) {
1116
1116
return false ;
1117
1117
}
1118
1118
$ end = $ this ->findXmlBlockEnd ($ start , $ blockType );
1119
- if (0 > $ end ) {
1120
- return false ;
1121
- }
1122
-
1123
- return array ('start ' => $ start , 'end ' => $ end );
1124
- }
1125
-
1126
- /**
1127
- * Find start and end of XML block containing the given block macro
1128
- * e.g. <w:p>...${macro}...${/macro}...</w:p>
1129
- *
1130
- * Note that only the first instance of the macro will be found
1131
- *
1132
- * @param string $macro Name of macro
1133
- * @param string $blockType XML tag for block
1134
- * @return bool|int[] FALSE if not found, otherwise array with start and end
1135
- */
1136
- protected function findContainingXmlBlockForBlockMacro ($ macro , $ blockType = 'w:p ' )
1137
- {
1138
- $ macroStartPos = $ this ->findMacro ($ macro );
1139
- if (0 > $ macroStartPos ) {
1140
- return false ;
1141
- }
1142
- $ macroEndPos = $ this ->findMacro ('/ ' . $ macro , $ macroStartPos );
1143
- if (0 > $ macroEndPos ) {
1144
- return false ;
1145
- }
1146
- $ start = $ this ->findXmlBlockStart ($ macroStartPos , $ blockType );
1147
- if (0 > $ start ) {
1148
- return false ;
1149
- }
1150
- $ end = $ this ->findXmlBlockEnd ($ macroEndPos , $ blockType );
1151
- if (0 > $ end ) {
1119
+ //if not found or if resulting string does not contain the macro we are searching for
1120
+ if (0 > $ end || strstr ($ this ->getSlice ($ start , $ end ), $ macro ) === false ) {
1152
1121
return false ;
1153
1122
}
1154
1123
@@ -1183,12 +1152,13 @@ protected function findMacro($search, $offset = 0)
1183
1152
*/
1184
1153
protected function findXmlBlockStart ($ offset , $ blockType )
1185
1154
{
1155
+ $ reverseOffset = (strlen ($ this ->tempDocumentMainPart ) - $ offset ) * -1 ;
1186
1156
// first try XML tag with attributes
1187
- $ blockStart = strrpos ($ this ->tempDocumentMainPart , '< ' . $ blockType . ' ' , (( strlen ( $ this -> tempDocumentMainPart ) - $ offset ) * - 1 ) );
1157
+ $ blockStart = strrpos ($ this ->tempDocumentMainPart , '< ' . $ blockType . ' ' , $ reverseOffset );
1188
1158
// if not found, or if found but contains the XML tag without attribute
1189
1159
if (false === $ blockStart || strrpos ($ this ->getSlice ($ blockStart , $ offset ), '< ' . $ blockType . '> ' )) {
1190
1160
// also try XML tag without attributes
1191
- $ blockStart = strrpos ($ this ->tempDocumentMainPart , '< ' . $ blockType . '> ' , (( strlen ( $ this -> tempDocumentMainPart ) - $ offset ) * - 1 ) );
1161
+ $ blockStart = strrpos ($ this ->tempDocumentMainPart , '< ' . $ blockType . '> ' , $ reverseOffset );
1192
1162
}
1193
1163
1194
1164
return ($ blockStart === false ) ? -1 : $ blockStart ;
0 commit comments