コード例 #1
0
 static function f_Xml_GetPart(&$Txt, $TagLst, $AllIfNothing = false)
 {
     // Returns parts of the XML/HTML content, default is BODY.
     if ($TagLst === true or $TagLst === '') {
         $TagLst = 'body';
     }
     $x = '';
     $nothing = true;
     $TagLst = explode('+', $TagLst);
     // Build a clean list of tags
     foreach ($TagLst as $i => $t) {
         if (substr($t, 0, 1) == '(' and substr($t, -1, 1) == ')') {
             $t = substr($t, 1, strlen($t) - 2);
             $Keep = true;
         } else {
             $Keep = false;
         }
         $TagLst[$i] = array('t' => $t, 'k' => $Keep, 'b' => -1, 'e' => -1, 's' => false);
     }
     $PosOut = strlen($Txt);
     $Pos = 0;
     do {
         // Search new positions
         $TagMin = false;
         $PosMin = $PosOut;
         foreach ($TagLst as $i => $Tag) {
             if ($Tag['b'] < $Pos) {
                 $Loc = clsTinyButStrong::f_Xml_FindTag($Txt, $Tag['t'], true, $Pos, true, false, false);
                 if ($Loc === false) {
                     $Tag['b'] = $PosOut;
                     // tag not found, no more search on this tag
                 } else {
                     $Tag['b'] = $Loc->PosBeg;
                     $Tag['e'] = $Loc->PosEnd;
                     $Tag['s'] = substr($Txt, $Loc->PosEnd - 1, 1) === '/';
                     // true if it's a single tag
                 }
                 $TagLst[$i] = $Tag;
                 // update
             }
             if ($Tag['b'] < $PosMin) {
                 $TagMin = $i;
                 $PosMin = $Loc->PosBeg;
             }
         }
         // Add the part
         if ($TagMin !== false) {
             $Tag =& $TagLst[$TagMin];
             $Pos = $Tag['e'] + 1;
             if ($Tag['s']) {
                 // single tag
                 if ($Tag['k']) {
                     $x .= substr($Txt, $Tag['b'], $Tag['e'] - $Tag['b'] + 1);
                 }
             } else {
                 // search the closing tag
                 $Loc = clsTinyButStrong::f_Xml_FindTag($Txt, $Tag['t'], false, $Pos, true, false, false);
                 if ($Loc === false) {
                     $Tag['b'] = $PosOut;
                     // closing tag not found, no more search on this tag
                 } else {
                     $nothing = false;
                     if ($Tag['k']) {
                         $x .= substr($Txt, $Tag['b'], $Loc->PosEnd - $Tag['b'] + 1);
                     } else {
                         $x .= substr($Txt, $Tag['e'] + 1, $Loc->PosBeg - $Tag['e'] - 1);
                     }
                     $Pos = $Loc->PosEnd + 1;
                 }
             }
         }
     } while ($TagMin !== false);
     if ($AllIfNothing and $nothing) {
         return $Txt;
     }
     return $x;
 }
コード例 #2
0
 function FindEndTag($Encaps = false)
 {
     if (is_null($this->SelfClosing)) {
         $pe = $this->PosEnd;
         $SelfClosing = substr($this->Txt, $pe - 1, 1) == '/';
         if (!$SelfClosing) {
             if ($Encaps) {
                 $loc = clsTinyButStrong::f_Xml_FindTag($this->Txt, $this->FindName(), null, $pe, true, -1, false, false);
                 if ($loc === false) {
                     return false;
                 }
                 $this->pET_PosBeg = $loc->PosBeg;
                 $this->PosEnd = $loc->PosEnd;
             } else {
                 $pe = clsTinyButStrong::f_Xml_FindTagStart($this->Txt, $this->FindName(), false, $pe, true, true);
                 if ($pe === false) {
                     return false;
                 }
                 $this->pET_PosBeg = $pe;
                 $pe = strpos($this->Txt, '>', $pe);
                 if ($pe === false) {
                     return false;
                 }
                 $this->PosEnd = $pe;
             }
         }
         $this->SelfClosing = $SelfClosing;
     }
     return true;
 }
コード例 #3
0
ファイル: tinyButStrong.class.php プロジェクト: rhertzog/lcs
function f_Xml_GetPart(&$Txt,$Tag,$KeepTags=false,$AllIfNothing=false) {
// This function returns a part of the HTML document, default is BODY.

	if (($Tag===true) or ($Tag==='')) $Tag = 'BODY';

	$x = false;

	if ($LocOpen = clsTinyButStrong::f_Xml_FindTag($Txt,$Tag,true,0,true,false,false)) {
		if ($LocClose = clsTinyButStrong::f_Xml_FindTag($Txt,$Tag,false,$LocOpen->PosEnd+1,true,false,false)) {
			if ($KeepTags) {
				$x = substr($Txt,$LocOpen->PosBeg,$LocClose->PosEnd - $LocOpen->PosBeg + 1);
			} else {
				$x = substr($Txt,$LocOpen->PosEnd+1,$LocClose->PosBeg - $LocOpen->PosEnd - 1);
			}
		}
	}

	if ($x===false) $x = ($AllIfNothing) ? $Txt : '';

	return $x;

}
コード例 #4
0
 function OpenDoc_SheetDeleteAndDisplay()
 {
     if (!isset($this->OtbsSheetOk)) {
         return;
     }
     if (count($this->OtbsSheetDelete) == 0 && count($this->OtbsSheetVisible) == 0) {
         return;
     }
     $this->OpenDoc_SheetInit(true);
     $Txt = $this->TbsStoreGet($this->OpenDoc_Sheets_FileId, 'Sheet Delete and Display');
     $close = '</table:table>';
     $close_len = strlen($close);
     $styles_to_edit = array();
     // process sheet in rever order of their positions
     for ($idx = count($this->OpenDoc_Sheets) - 1; $idx >= 0; $idx--) {
         $loc = $this->OpenDoc_Sheets[$idx];
         $id = 'i:' . ($idx + 1);
         $name = 'n:' . $loc->PrmLst['table:name'];
         if (isset($this->OtbsSheetDelete[$name]) || isset($this->OtbsSheetDelete[$id])) {
             // Delete the sheet
             $p = strpos($Txt, $close, $loc->PosEnd);
             if ($p === false) {
                 return;
             }
             // XML error
             $Txt = substr_replace($Txt, '', $loc->PosBeg, $p + $close_len - $loc->PosBeg);
             unset($this->OtbsSheetDelete[$name]);
             unset($this->OtbsSheetDelete[$id]);
             unset($this->OtbsSheetVisible[$name]);
             unset($this->OtbsSheetVisible[$id]);
         } elseif (isset($this->OtbsSheetVisible[$name]) || isset($this->OtbsSheetVisible[$id])) {
             // Hide or dispay the sheet
             $visible = isset($this->OtbsSheetVisible[$name]) ? $this->OtbsSheetVisible[$name] : $this->OtbsSheetVisible[$id];
             $visible = $visible ? 'true' : 'false';
             if (isset($loc->PrmLst['table:style-name'])) {
                 $style = $loc->PrmLst['table:style-name'];
                 $new = $style . '_tbs_' . $visible;
                 if (!isset($styles_to_edit[$style])) {
                     $styles_to_edit[$style] = array();
                 }
                 $styles_to_edit[$style][$visible] = $new;
                 // mark the style to be edited
                 $pi = $loc->PrmPos['table:style-name'];
                 $Txt = substr_replace($Txt, $pi[4] . $new . $pi[4], $pi[2], $pi[3] - $pi[2]);
             }
             unset($this->OtbsSheetVisible[$name]);
             unset($this->OtbsSheetVisible[$id]);
         }
     }
     // process styles to edit
     if (count($styles_to_edit) > 0) {
         $close = '</style:style>';
         $close_len = strlen($close);
         $p = 0;
         while ($loc = clsTinyButStrong::f_Xml_FindTag($Txt, 'style:style', true, $p, true, false, true, false)) {
             $p = $loc->PosEnd;
             if (isset($loc->PrmLst['style:name'])) {
                 $name = $loc->PrmLst['style:name'];
                 if (isset($styles_to_edit[$name])) {
                     // retrieve the full source of the <style:style> element
                     $p = strpos($Txt, $close, $p);
                     if ($p === false) {
                         return;
                     }
                     // bug in the XML contents
                     $p = $p + $close_len;
                     $src = substr($Txt, $loc->PosBeg, $p - $loc->PosBeg);
                     // add the attribute, if missing
                     if (strpos($src, ' table:display="') === false) {
                         $src = str_replace('<style:table-properties ', '<style:table-properties table:display="true" ', $src);
                     }
                     // add new styles
                     foreach ($styles_to_edit[$name] as $visible => $newName) {
                         $not = $visible === 'true' ? 'false' : 'true';
                         $src2 = str_replace(' style:name="' . $name . '"', ' style:name="' . $newName . '"', $src);
                         $src2 = str_replace(' table:display="' . $not . '"', ' table:display="' . $visible . '"', $src2);
                         $Txt = substr_replace($Txt, $src2, $loc->PosBeg, 0);
                         $p = $p + strlen($src2);
                     }
                 }
             }
         }
     }
     // store the result
     $this->TbsStorePut($this->OpenDoc_Sheets_FileId, $Txt);
     $this->TbsSheetCheck();
 }
コード例 #5
0
 function f_Xml_GetPart(&$Txt, $TagLst, $AllIfNothing = false)
 {
     // Returns parts of the XML/HTML content, default is BODY.
     if ($TagLst === true or $TagLst === '') {
         $Tag = 'BODY';
     }
     $x = '';
     $nothing = true;
     $TagLst = explode('+', $TagLst);
     foreach ($TagLst as $Tag) {
         $Tag = trim($Tag);
         $KeepTags = false;
         if (substr($Tag, 0, 1) == '(' and substr($Tag, -1, 1) == ')') {
             $Tag = substr($Tag, 1, strlen($Tag) - 2);
             $KeepTags = true;
         }
         $Pos = 0;
         while ($LocOpen = clsTinyButStrong::f_Xml_FindTag($Txt, $Tag, true, $Pos, true, false, false)) {
             $Pos = $LocOpen->PosEnd + 1;
             if ($LocClose = clsTinyButStrong::f_Xml_FindTag($Txt, $Tag, false, $Pos, true, false, false)) {
                 $Pos = $LocClose->PosEnd;
                 $nothing = false;
                 if ($KeepTags) {
                     $x .= substr($Txt, $LocOpen->PosBeg, $LocClose->PosEnd - $LocOpen->PosBeg + 1);
                 } else {
                     $x .= substr($Txt, $LocOpen->PosEnd + 1, $LocClose->PosBeg - $LocOpen->PosEnd - 1);
                 }
             }
         }
     }
     if ($AllIfNothing and $nothing) {
         return $Txt;
     }
     return $x;
 }
コード例 #6
0
 function tag_DelOptionalTableAtt()
 {
     // Two Table attributes give the size of the zone, this zone may be extended after a MergeBlock()
     // Hopefully, those attributes are optional, so we delete them.
     $Txt =& $this->TBS->Source;
     $att_lst = array('ss:ExpandedColumnCount', 'ss:ExpandedRowCount');
     $Pos = 0;
     while (($Loc = clsTinyButStrong::f_Xml_FindTag($Txt, 'Table', true, $Pos, true, false, true, true)) !== false) {
         foreach ($att_lst as $att) {
             // delete the attributes by replacing them with spaces
             $att = strtolower($att);
             // The TBS method does turn attributes anmes into lowercase.
             if (isset($Loc->PrmPos[$att])) {
                 $p = $Loc->PrmPos[$att];
                 $n = $p[3] - $p[0] + 1;
                 $Txt = substr_replace($Txt, str_repeat(' ', $n), $p[0], $n);
             }
         }
         $Pos = $Loc->PosEnd + 1;
     }
 }