function f_Loc_EnlargeToTag(&$Txt, &$Loc, $TagStr, $RetInnerSrc) { //Modify $Loc, return false if tags not found, returns the inner source of tag if $RetInnerSrc=true $AliasLst =& $GLOBALS['_TBS_BlockAlias']; // Analyze string $Ref = 0; $LevelStop = 0; $i = 0; $TagFct = array(); $TagLst = array(); while ($TagStr !== '') { // get next tag $p = strpos($TagStr, '+'); if ($p === false) { $t = $TagStr; $TagStr = ''; } else { $t = substr($TagStr, 0, $p); $TagStr = substr($TagStr, $p + 1); } do { // Check parentheses, relative position and single tag $t = trim($t); $e = strlen($t) - 1; // pos of last char if ($e > 1 && $t[0] === '(' && $t[$e] === ')') { if ($Ref === 0) { $Ref = $i; } if ($Ref === $i) { $LevelStop++; } $t = substr($t, 1, $e - 1); } else { if ($e >= 0 && $t[$e] === '/') { $t = substr($t, 0, $e); } // for compatibilty $e = false; } } while ($e !== false); if (isset($AliasLst[$t])) { $a = $AliasLst[$t]; if (is_string($a)) { if ($i > 999) { return false; } // prevent from circular alias $TagStr = $TagStr === '' ? $a : $a . '+' . $TagStr; } else { $TagLst[$i] = $t; $TagFct[$i] = $a; $i++; } } else { $TagLst[$i] = $t; $TagFct[$i] = false; $i++; } } $TagMax = $i - 1; // Find tags that embeds the locator if ($LevelStop === 0) { $LevelStop = 1; } // First tag of reference $TagO = clsTinyButStrong::f_Loc_Enlarge_Find($Txt, $TagLst[$Ref], $TagFct[$Ref], $Loc->PosBeg - 1, false, $LevelStop); if ($TagO === false) { return false; } $PosBeg = $TagO->PosBeg; $LevelStop += -$TagO->RightLevel; // RightLevel=1 only if the tag is single and embeds $Loc, otherwise it is 0 if ($LevelStop > 0) { $TagC = clsTinyButStrong::f_Loc_Enlarge_Find($Txt, $TagLst[$Ref], $TagFct[$Ref], $Loc->PosEnd + 1, true, -$LevelStop); if ($TagC == false) { return false; } $PosEnd = $TagC->PosEnd; $InnerLim = $TagC->PosBeg; } else { $PosEnd = $TagO->PosEnd; $InnerLim = $PosEnd + 1; } $RetVal = true; if ($RetInnerSrc) { $RetVal = ''; if ($Loc->PosBeg > $TagO->PosEnd) { $RetVal .= substr($Txt, $TagO->PosEnd + 1, min($Loc->PosBeg, $InnerLim) - $TagO->PosEnd - 1); } if ($Loc->PosEnd < $InnerLim) { $RetVal .= substr($Txt, max($Loc->PosEnd, $TagO->PosEnd) + 1, $InnerLim - max($Loc->PosEnd, $TagO->PosEnd) - 1); } } // Other tags forward $TagC = true; for ($i = $Ref + 1; $i <= $TagMax; $i++) { $x = $TagLst[$i]; if ($x !== '' && $TagC !== false) { $TagC = clsTinyButStrong::f_Loc_Enlarge_Find($Txt, $x, $TagFct[$i], $PosEnd + 1, true, 0); if ($TagC !== false) { $PosEnd = $TagC->PosEnd; } } } // Other tags backward $TagO = true; for ($i = $Ref - 1; $i >= 0; $i--) { $x = $TagLst[$i]; if ($x !== '' && $TagO !== false) { $TagO = clsTinyButStrong::f_Loc_Enlarge_Find($Txt, $x, $TagFct[$i], $PosBeg - 1, false, 0); if ($TagO !== false) { $PosBeg = $TagO->PosBeg; } } } $Loc->PosBeg = $PosBeg; $Loc->PosEnd = $PosEnd; return $RetVal; }