Abiword to prosty edytor ala word/openoffice writer tyle że prostszy. Do pobrania dla wielu systemów na stronie aplikacji smile.gif
Poniższy skrypt przerobi plik abw na jako taki HTML smile.gif Wymaga PHP5+SimpleXML. Jeżeli plik zawiera grafiki to skryp będzie chciał je zapisać do bierzącego katalogu (wymagane uprawnienia zapisu)
  1. <?php
  2. echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>';
  3. // read content
  4. $data = file_get_contents('a.abw'); // NAZWA PLIKU
  5. // tekst
  6. preg_match_all('#<section(.*?)>(.*?)</section>#es', $data, $text);
  7. $texts = $text[2];
  8. unset($text);
  9. // grafika
  10. preg_match_all('#<data>(.*?)</data>#es', $data, $extra);
  11. $extras = $extra[0];
  12. unset($extra);
  13. unset($data);
  14.  
  15. $texts = implode('', $texts);
  16. IF(is_array($extras))
  17.     {
  18.     // jeżeli są grafiki /załączniki to pojedź dalej
  19.     $extras = implode('', $extras);
  20.     $xml = simplexml_load_string($extras);
  21.     $iter = 0;
  22.     IF(is_object($xml->d))
  23.         {
  24.         foreach($xml->d as $d)
  25.             {
  26.             IF(ereg('image/([a-z]*)', $xml->d['mime-type'], $tab))
  27.                 {
  28.                 $filename = md5($xml->d[$iter]['name']);
  29.                 $image_content = base64_decode($xml->d[$iter]);
  30.                 $images[$filename] = $filename.'.'.$tab[1];
  31.                 file_put_contents($filename.'.'.$tab[1], $image_content);
  32.                 $iter++;
  33.                 }
  34.             }
  35.         unset($iter);
  36.         // przerabiamy wywołania do grafik na img src
  37.         preg_match_all('#<image dataid="(.*?)" (.*?)"/>#es', $texts, $img);
  38.         foreach($img[1] as $key => $val)
  39.             {
  40.             $val = md5($val);
  41.             $texts = str_replace($img[0][$key], '<img src="'.$images[$val].'">', $texts);
  42.             }
  43.         unset($img);
  44.         }
  45.     }
  46. // tabelki
  47. preg_match_all('#<cell props="bot-attach:([0-9]*); left-attach:([0-9]*); right-attach:([0-9]*); top-attach:([0-9]*)">#es', $texts, $table);
  48. $tr = 0;
  49. foreach($table[0] as $key => $val)
  50.     {
  51.     IF($tr != $table[4][$key])
  52.         {
  53.         $texts = str_replace($val, '</tr><tr><td>', $texts);
  54.         $tr = $table[4][$key];
  55.         }
  56.     else
  57.         {
  58.         $texts = str_replace($val, '<td>', $texts);
  59.         }
  60.     }
  61. unset($table);
  62. unset($tr);
  63. // wypunktowanie
  64. preg_match_all('#<c props="([a-zA-Z0-9 _;:-]*) list-style:Bullet List; ([a-zA-Z0-9 _;:-]*)">(.*?)</c>#es', $texts, $li);
  65. foreach($li[0] as $key => $val)
  66.     {
  67.     $texts = str_replace($val, '<LI>'.$li[3][$key].'</LI>', $texts);
  68.     }
  69.  
  70. preg_match_all('#<p level="(.*?) list-style:Numbered List; ([a-zA-Z0-9 _;:-]*)">(.*?)</p>#es', $texts, $li2);
  71. foreach($li2[0] as $key => $val)
  72.     {
  73.     $texts = str_replace($val, '<LI>'.$li2[3][$key].'</LI>', $texts);
  74.     }
  75. unset($li2);
  76. // czyszczenie, poprawki
  77. $texts= preg_replace('#<field (.*?)></field>#es', '', $texts);
  78. $texts = strtr($texts, array('<c props' => '<div style', '</c>' => '</div>', 'props="' => 'style="', '</cell>' => '</td>', '<table>' => '<table border="1" width="100%"><tr>', '</table>' => '</tr></table>', '</field>' => ''));
  79. //highlight_string($texts);
  80. //echo '<BR><BR><HR><BR>';
  81. // kod HTML jest cienki ale ujdzie.. albo do Tidy albo do ręcznych poprawek
  82. echo $texts;
  83. ?>
  84. </body></html>